2017 m. gruodžio 14 d., ketvirtadienis

stellar

Official website: https://www.stellar.org/
Buying stellar:
https://stellarterm.com/
http://yicex.com/

Stellar testnet
https://www.stellar.org/developers/guides/concepts/test-net.html
https://github.com/stellar/stellar-core/blob/master/docs/stellar-core_testnet.cfg

Discussion:
https://galactictalk.org/
https://stellar.stackexchange.com - Stack exchange for questions.


The stellar development foundation runs two horizon servers:
https://horizon.stellar.org
https://horizon-testnet.stellar.org.

Stellar laboratory (place where you can test)
https://www.stellar.org/laboratory/#account-creator?network=test

Stellar expert (Block explorer)
https://stellar.expert/explorer/asset/native 

Build challange
https://www.stellar.org/lumens/build/

Services:
https://stellar.expert/explorer/  - Block explorer and analytics platform for Stellar Network.
https://steexp.com - stellar explorer
https://stellar.debtmoney.xyz/
https://stellardesk.org/  - Stellar desk
http://stellar-price.com - Find best stellar prices
https://www.fedcloud.info/ - Custom dns names

Wallets:
https://lobstr.co/
http://luuun.com/
https://astralwallet.io/

Online:
https://stellarterm.com/#account
https://www.stellar.org/account-viewer/#!/

Horizon is the client-facing API server for the Stellar ecosystem.
It acts as the interface between Stellar Core and applications that want to access the Stellar network. Horizon allows you to submit transactions to the network, check the status of accounts, and subscribe to event streams.

Virtual API in Horizon
  • History API
    provides list of transations
  • Transaction Submission API
  • Trading APi

Resourses
/transaction/....../operation
FILTER             TYPE


/efects - every change in account history
/efects/ledgers/1 - filter
/transaction/...hash..../efects - efects by transaction
/transaction/...hash..../operations - selecting specification what changes was made to leadger

Responses:
json response
links are expresing relationships between  various objects, that are expressed in history API

Video:
Horizon: API webserver for the Stellar network

2017 m. gruodžio 8 d., penktadienis

etherium cryptokitties


Trait explanations

Metamask explanation


How to fix successful but  no txn hash found!


  1. Clear Browser cookies and cache
  2. Close out of all windows in your Browser
  3. WAIT FOR 10 SECONDS
  4. Log back into metamask using your mnemonic keyphrase (12 words)
  5. Log back into CryptoKitties with your same email and username!
  6. Follow these instructions please~
  7. It's a client side issue so this should fix it.



Link:
https://www.cryptokitties.co
http://www.kitty.services/ - Predict offspring
http://www.kittyexplorer.com/ - Kitty explorer
https://catstats.io/ - Crypto cats stat

https://github.com/HaJaeKyung/KittyExtension  - tampermokey  extention -

Etherium links

https://etherscan.io - Blokų eksploreris
https://ethgasstation.info/ - Etherium degalinė
https://blockstack.org/ - Creating daps
Metamask - Naršyklės papildinys

ENS - Etherio vardų serveriai.

Dapps:
https://dappradar.com/ - Dappsų sarašas.
https://www.cryptokitties.co - kripto katinėliai.

What to do:
http://bountyone.io/bounties - bounty for projects
https://bitcointalk.org/index.php?topic=3944546.msg37672781#msg37672781  expance projektai

2017 m. gruodžio 4 d., pirmadienis

Bitcoin Pagrindinės sąvokos ir apibrėžimai

Bitcoin (neskaičiuotinas daiktavardis) – Bitcoin yra projekto pavadinimas, kurio pradininkas yra Satoshi Nakamoto. Bitcoin taip pat yra kriptovaliutos pavadinimas.

Bitcoinai (angl. Bitcoins) (skaičiuotinas daiktavardis) – Bitcoin, taip pat trumpinama kaip BTC. 1/1000000 valiutos dalis kūrėjo garbei pavadinta – satoshi.

Adresas (angl. Address ) arba Bitcoin adresas - tai 27-34 raidžių ir skaitmenų identifikatorius, kuris prasideda 1 arba 3, apibrėžiant galimo bitcoin mokėjimo paskirties vietą.

Pavedimas (angl.Transaction) – tranzakcija yra vienetinė operacija, kurios metu perkeliame bitcoiną iš vieno adreso į kitą.

Blokas (angl. Block) – informacijos įrašas, talpinantis pavedimus, įvykdytus po paskutinio patvirtino bloko.

Blokų grandinė (angl. Block Chain) – tai rinkinys visų blokų, kuriais dalinasi sistemoje dalyvaujantys mazgai.

Pradinis blokas (angl. Genesis Block ) – tai blokas, kuris buvo įkoduotas į standartinį klientą, kad būtų naudojamas kaip blokų grandinės pradžios taškas.

Klientas (angl. Client ) – tai aplikacija, skirta vartotojui. Naudojama atlikti operacijoms Bitcoin tinkle.

Standartinis Klientas (angl. Standard Client) – originalus klientas, kurtas Bitcoin projekto kūrėjo, jis nusako, kaip turėtų tarpusavyje dirbti klientai.

Tinklas (angl. Network ) – Bitcoin tinklas yra bendras pavadinimas visų tarpusavyje sujungtų aplikacijų, kurios keičiasi informacija apie blokus, tranzakcijas ir prijungtus klientus.

Piniginė (angl. Wallet ) – adresų grupė, sukurta kliento ir saugoma lokaliame dokumente.

Kasėjas (angl. Miner) – kompiuterio mašina, kurioje vykdoma programa skirta išspręsti ar „iškasti“ naujus blokus.

Python Mock

Python 3

Mocking library
>>> import requests
>>> from unittest.mock import Mock

Inheriting all request methods with mock

>>> mock = Mock(spec=requests)
 >>> mock.get()
<Mock name='mock.get()' id='139987415228200'>

Adding return value
>>> mail = mock.MagicMock(spec=Mail)
>>>subject = mail.method_name = "42"


Resources:
https://python-mock-tutorial.readthedocs.io/en/latest/mock.html

Usefull pycharm plugins

SonarPython -  Static code analyzer 
Grep-debug  - To change default red pycharm debug log 

python dictionary variable unpacking

>>> def color(red, green, blue, **kwargs):
...     print("r=", red)
...     print("g=", green)
...     print("b=", blue)
...     print(kwargs)


>>> k = {'red':10, 'green':11, 'blue':22, 'alpha':20}
>>> k = dict(red=10, green=11, blue=22, alpha=20) #or

>>> color(**k)
('r=', 10)
('g=', 11)
('b=', 22)
{'alpha': 20}

2017 m. lapkričio 28 d., antradienis

Python debugging with pdb

Insert this line, where you want to debug your code:

>>> import pdb; pdb.set_trace()

pdb commands:

h - help
n - step 
l - display where are you
s - step in
r - return

q - quit
p - print values

Change pycharm max line length

Modify Max length of the line (Pylint maximum allowed line width) - 100

How to change:

Editor -> Code Style
Right margin (columns) = 100




Creating crypto

 Here is some relevant code from main.h:

static const int64 MIN_TX_FEE = 0.1 * CENT;
static const int64 MIN_RELAY_TX_FEE = 0.1 * CENT;
static const int64 MAX_MONEY = 2000000000 * COIN;
static const int64 MAX_MINT_PROOF_OF_WORK = 9999 * COIN;
static const int64 MIN_TXOUT_AMOUNT = MIN_TX_FEE;
static const int STAKE_TARGET_SPACING = 1 * 60; // 1-minute block
static const int STAKE_MIN_AGE = 60 * 60; // minimum age for coin age
static const int STAKE_MAX_AGE = 60 * 60 * 24 * 5; // stake age of full weight
static const int STAKE_START_TIME = 1418470264; // Sat 13 Dec 2014 06:31:04 AM EST
static const unsigned int POW_START_TIME = 1418403600; // Fri 12 Dec 2014 12:00:00 PM EST
static const unsigned int POW_END_TIME = 1419181200; // Sun 21 Dec 2014 12:00:00 PM EST
static const unsigned int MODIFIER_INTERVAL = 10 * 60;
static const int64 NUMBER_OF_PRIMENODE = 50;
static const int64 MINIMUM_FOR_ORION = 50 * COIN;
static const int64 MINIMUM_FOR_PRIMENODE = 125000 * COIN;

Create a new genesis block.
Once set it will look something like this:

static const uint256 hashGenesisBlockOfficial("0x0");
block.nNonce = 0;
assert(block.hashMerkleRoot == uint256("0x0"));

Resources-tutorials:
https://themerkle.com/altcoins-dying-make-one-hour/
https://youtu.be/86jqAfySi64 - tutorial making your own crypto
https://build-a-co.in - crypto currency generator



Kriptovaliutos kūrimas pirminio kodo keitimas

Kad įsitikintume, ar prievadai neužimti peržiūrime okupuotų prievadų lentelę, kurią galime rasti – (https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers) .

src/init.cpp: (P2P PORT + Testnet Port)
 LINE 235 "  -port= " + _("Listen for connections on  (default: 55884 or testnet: 45884)") + "\n" +
src/init.cpp: (RPC PORT)
 LINE 271 "  -rpcport= " + _("Listen for JSON-RPC connections on  (default: 55883)") + "\n" +

Tolesni nustatymai aprašo monetų generavimo intervalus, sudėtingumo perskaičiavimo laiką.
src/main.cpp: (Monetų kiekis, kurį gauna kasėjai suradę bloką)
 LINE 831 int64 nSubsidy = 1 * COIN;
 LINE 832 if(nHeight < 10) // pirmas motetos po 10 bloko
src/main.cpp: (Parodo kas kiek laiko keičiamas sudėtingumo lygis)
 LINE 837 static const int64 nTargetTimespan = 0.35 * 24 * 60 * 60 //0.35 blokų perskaičiavimo laikas
 LINE 836 static const int64 nTargetSpacing = 15; // blokų generavimas kas 15s

src/main.h: (Bendras monetų kiekis ir Blokų skaičius per parą)
LINE 43 static const int64 MAX_MONEY = 10000 * COIN; // maksimalus monetų kiekis
LINE 550 return dPriority > COIN * 720 / 250; // 720 blokai randami per parą.

Pirma adreso raidė yra parenkama naudojant base58 algoritmą. Pagal puslapį, base58 reikšmes galima rasti puslapyje (https://en.bitcoin.it/wiki/Base58Check_encoding).
src/base58.h:
 LINE 280 PUBKEY_ADDRESS = 38, //Nurodomas adreso pirmas bitas

Eros laikas
Pirmas dalykas, kurį turime pakeisti prieš pradedant generuoti blokus, tai pradinis monetos gimimo laikas. Nuo vidurnakčio 1970 metų 00:00:00 Unix (Epoch ar POSIX) buvo pradėtas skaičiuoti laikas . Žemiau pateikiamas pavyzdys:
398419697 (ISO 8601:2014-04-25T09:54:57Z)
Tikslų epochos laiką randame (http://www.epochconverter.com) su galimybe apskaičiuoti būsimą epochos laiką.
Unix sistemoje laikas randamas komanda:
$ date +%s
$ 1369590088
Yra dvi pagrindinės vietos, kuriose reikia pakeisti laiką pirminiame kode.
src/main.cpp: (Tesnet laikas)
 LINE 2034 block.nTime    = 1398459635;
src/main.cpp: (Pagrindinis laikas)
 LINE 2040 block.nTime    = 1398459635;

Kompiliavimas
Dabar atlikę pakeitimus, galime pradėti sukompiliuoti barcoin failą. Kompiliuojame naudodami komandą:
barcoin/src% make -f makefile.unix USE_UPNP=-

Paleidžiame sukompiliuotą programą tesnet režimu:

root@Projektas:~/barcoin/src# ./barcoin -testnetd
barcoin: main.cpp:2082: bool LoadBlockIndex(bool): Assertion `block.GetHash() == hashGenesisBlock' failed.
Aborted
root@Projektas:~/barcoin/src# LoadBlockIndex(bool): Assertion `block.GetHash() == hashGenesisBlock' failed.

/debug.log
Gfcoin version v0.6.3.0-ga19eb2d-beta (2014-04-25 22:58:31 +0300)
Startup time: 04/26/14 10:44:51
Default data directory /root/.gfcoin
Used data directory /root/.gfcoin
Bound to [::]:29931
Bound to 0.0.0.0:29931
Loading block index...
dbenv.open LogDir=/root/.gfcoin/database ErrorFile=/root/.gfcoin/db.log
800426389bc34c1f79fe330efcc6e5f187821a4f69a7982d3c46c58df442f21f
384b060671f4a93948e9c168216dadb0ca2fbc54aa11c86b0345b6af1c59b2f5
5a2e19825b4162f68602039040f1e05d9f924ff00a3aff7327ca6abd6f3279bc
CBlock(hash=800426389bc34c1f79fe, PoW=837b089eb934d1dd50e9, ver=1, hashPrevBlock=00000000000000000000, hashMerkleRoot=5a2e19825b, nTime=1398459635, nBits=1e0ffff0, nNonce=2085386442, vtx=1)
CTransaction(hash=5a2e19825b, ver=1, vin.size=1, vout.size=1, nLockTime=0)
CTxIn(COutPoint(0000000000, -1), coinbase 04ffff001d010441746f646f3a207265706c616365207769746820736f6d657468696e67207468617420656e7375726573206e6f207072656d696e696e6720746f6f6b20706c616365)
CTxOut(error)
vMerkleTree: 5a2e19825b

Ši eilute -
800426389bc34c1f79fe330efcc6e5f187821a4f69a7982d3c46c58df442f21f -  nusako bloką su neegzistuojančią Merkel maišą naudota main.cpp faile:

Žemiau nurodyta eilutė sugeneruota sugeneruoja teisingą Merkel maišą naudojant epochos laiką iš main.cpp dokumento:
5a2e19825b4162f68602039040f1e05d9f924ff00a3aff7327ca6abd6f3279bc

Įrašome teisingai sugeneruota maišą main.cpp dokumente.
src/main.cpp
 LINE 2048 assert(block.hashMerkleRoot == uint256("0x5a2e19825b4162f68602039040f1e05d9f924ff00a3aff7327ca6abd6f3279bc"));

Kad būtų sukurtas Pradinis blokas, reikia pakeisti main.cpp eilutėlės reikšmę į true, ji paprastai nebūna nustatyta, nes reikalinga tik pirmojo bloko generavimui.

src/main.cpp
 LINE 2034 if (true && block.GetHash() != hashGenesisBlock)

Kad pakeitimai įsigaliotų klientas turi būtų perkompiliuotas
barcoin/src$ make -f makefile.unix

Atlikus pakeitimus, programa kompiliuojama. Dar karta paleidžiame programą.
barcoin/src$ ./ barcoin –testnet

3.3 Pradžios bloko generavimas
Pradinio bloko „kasimas“, tai veiksmas reikalaujantis daug kompiuterio resursų, debug.log dokumente galime matyti, kaip yra ieškoma bloko, keičiant nonce reikšmę. Pradinio bloko sprendimas gali užtrukti ilgą laiką.
/debug.log
block.nTime = 1000000000
nonce 00115000: hash = cbf6230ccf415873cd8c10b33c092943224d04458671cff39898ffb636b865dd (target = 00000ffff0000000000000000000000000000000000000000000000000000000)
nonce 00116000: hash = 8ed7cc737432e37c2617c57b01305e3aff041479bf1d5391dc234bc9935bfa4c (target = 00000ffff0000000000000000000000000000000000000000000000000000000)
nonce 00117000: hash = a44c797fd7bd0ef7211f092cbfa0a214e74f5b16929860b7001d8725df2562a7 (target = 00000ffff0000000000000000000000000000000000000000000000000000000)
nonce 00118000: hash = b2b3ec59ea20e29ca0024cdfda994bb759b633cd12695dc1e6126fed0ab67162 (target = 00000ffff0000000000000000000000000000000000000000000000000000000)
nonce 00119000: hash = 521e992768cdd42607ae9f064e98623686fc96f33c04630f8a973c35a3e381cc (target = 00000ffff0000000000000000000000000000000000000000000000000000000)
nonce 0011A000: hash = dbb91176dc6e9ca7559bda664fa2bc854c447969a41afb9593a8a3b0b45bafea (target = 00000ffff0000000000000000000000000000000000000000000000000000000)
nonce 0011B000: hash = 2dd8fa5990dda1be7595f30ce7d801de7a457aa687700badf895a085abd8f932 (target = 00000ffff0000000000000000000000000000000000000000000000000000000)
nonce 0011C000: hash = 7fa071b3217feda33745c967cc0226b8c47269588c8cbb8d4bc69822eda31cd5 (target = 00000ffff0000000000000000000000000000000000000000000000000000000)

block.nNonce = 1167091
block.GetHash = c528c52daedce24e8d7a735e7e947946f41b3b578dfbab6de7a2e28bb713a5a1
CBlock(hash=c528c52daedce24e8d7a, PoW=00000dc4adbe12efe41a, ver=1, hashPrevBlock=00000000000000000000, hashMerkleRoot=2fc1b7ef46, nTime=1000000000, nBits=1e0ffff0, nNonce=1167091, vtx=1)
  CTransaction(hash=2fc1b7ef46, ver=1, vin.size=1, vout.size=1, nLockTime=0)
    CTxIn(COutPoint(0000000000, -1), coinbase 04ffff001d0104284275696c64696e67206120636f696e20746f2073686f772074686520776f726c6420686f772e2e2e)
    CTxOut(error)

Kaip matome iš debug.log dokumento, buvo atrasta bloko maiša, kartu su ja matome none reikšmę.

block.nNonce = 1167091
 block.GetHash = c528c52daedce24e8d7a735e7e947946f41b3b578dfbab6de7a2e28bb713a5a1

Viskas kas mums lieka padaryti, tai pakeisti pradžios bloko atraštę ir nonce main.cpp dokumente.
src/main.cpp:
 LINE 1984 hashGenesisBlock = uint256("0xc528c52daedce24e8d7a735e7e947946f41b3b578dfbab6de7a2e28bb713a5a1");
Yes, you need to leave the 0x in front of the hashes. You also need to enter the nNonce:
src/main.cpp:
 LINE 2024 block.nNonce   = 1167091;

Dabar esame pasirengę padėti bandymus testent režime. Prisijungti prie kito kompiuterio yra gana sudėtinga. Reikės prijungti du kompiuterius su the -connect=x.x.x.x kintamuoju, įvedant IP adresą komanda:
barcoin/src% ./barcoin -testnet -connect= 88.223.50.210

barcoin/src% ./barcoin -testnet -connect= 188.226.131.112

Sėkmingai sujungus ir įvedus komanda getinfo gaunamas pranešimas.
barcoin/src%./barcoin getinfo                       
 {
     "version" : 1000000,
     "protocolversion" : 60001,
     "walletversion" : 60000,
     "balance" : 0.00000000,
     "blocks" : 0,
     "connections" : 1,
     "proxy" : "",
     "difficulty" : 0.00024414,
     "testnet" : true,
     "keypoololdest" : 1369621665,
     "keypoolsize" : 101,
     "paytxfee" : 0.00000000,
     "mininput" : 0.00010000,
     "errors" : ""
   }

3.4 Kriptovaliutos „kasimas“


Dabar kai klientai sujungti galima pradėti generuoti monetas naudodami komanda:
barcoin/src% ./barcoin setgenerate true 3

Skaičius 3 nurodo kiek gijų procesorius naudos blokų „kasimui“. Po kurio laiko išvysime kažką panašaus į:
barcoin/src% ./barcoin getmininginfo
 {
     "blocks" : 0,
     "currentblocksize" : 1000,
     "currentblocktx" : 0,
     "difficulty" : 0.00024414,
     "errors" : "",
     "generate" : true,
     "genproclimit" : 16,
     "hashespersec" : 1432,
     "networkhashps" : -9223372036854775808,
     "pooledtx" : 0,
     "testnet" : true
 }

2017 m. lapkričio 14 d., antradienis

python logging

Adds logger to usual projects:

logging.getLogger('flask_cors').level = logging.DEBUG

Logging to file for paramiko library

logging.getLogger('paramiko').setLevel(logging.DEBUG)
paramiko.util.log_to_file('foo.log')

2017 m. lapkričio 9 d., ketvirtadienis

Learn git intecatively

Naudingos linux komandos

Randa a didžiausius failus:

$ find / -type f -size +10M -exec ls -la {} 2>/dev/null \; | sort -n -k 5 | tail -1
$ du -a / 2>/dev/null | sort -n -r | head -n 10
$ du -a /home | sort -n -r | head -n 5

Randa didžiausius failus ir juos vykdo:

$ find / ! -path "*/usr/*" -type f -size +10M -exec ls -la {} 2>/dev/null \; | sort -n -k 5 | tail -2

Suranda mažus failus iki 1 baito:

$ find / ! -path "*/proc/*" -type f -size -1c -exec ls -la {} 2>/dev/null \;

Atspausdina 40 mažiausiu failų:

$ find / ! -path "*/proc/*" -type f -size -1c -exec ls -la {} 2>/dev/null \; | sort -n -k 5 | tail -40

Randa senesnius failus nei 5d ir didesnius nei 5MB

$ find /path/to/files* -mtime +5 -size -5M

Katalogų kopijavimas su spc:

$ scp -rp sourcedirectory user@dest:/path

Su ps radimas tik tam tikrų procesu:

$ ps -eo pid,user,fname | grep root
$ ps -ef | awk '{print $2,$8}'
$ ps -ef | awk '{print $2,$8}' >> /home/test1/1.txt

Tuščių eilučių skaičiavimas:

$ grep -c "^$" .profile

Randa failus, kuriems savininkas turi rwx teises:

$ ll | egrep "\-rwx"


Rasti, kas neturi bash shello:

$ grep nologin /etc/passwd


Space Exploration Games

SpaceEngine is a realistic virtual Universe you can explore on your computer. Windows only.

http://spaceengine.org

Universe Sandbox ² is a physics-based space simulator. For Windows, Mac, and Linux

http://universesandbox.com

2017 m. lapkričio 2 d., ketvirtadienis

How to add pylint in Pycharm

Install pylint

$ sudo pip install pylint  

$ which pylint
/usr/local/bin/pylint

Goto:
File -> Settings
External Tools -> Add new


Name: pylint
Description: Pylint as external tool
Program: /usr/local/bin/pylint
Parameters: $FilePath$
Working directory: $ProjectFileDir$

How to close unresponsive ssh session

+ . + Enter

2017 m. lapkričio 1 d., trečiadienis

2017 m. spalio 23 d., pirmadienis

Crypto svetainės ir resursai

Naujienos:

https://www.ccn.com/
https://www.reddit.com/r/CryptoCurrency/

ICO:

https://www.icoalert.com/

Kriptovaliutų kainos:

 CoinMarketCap: https://coinmarketcap.com/
 BitScreener: https://bitscreener.com/
 BTC > USD/EUR skaičiuoklė: http://www.btcsatoshi.com/

Grafikai:

https://rollercoasterguy.github.io/
TradingView [Coinbase (GDAX), Bitstamp, Bitfinex, Poloniex, Bittrex]: https://www.tradingview.com/
Coinigy [Dauguma Exchanges, taip pat "Shitcoin Exchanges" kaip Cryptopia, YoBit]: https://www.coinigy.com/
CryptoWatch: https://cryptowat.ch/

Forumai:

Bitcointalk: https://bitcointalk.org/
Bitcointalk Altcoins temos: https://bitcointalk.org/index.php?board=159.0
Traders.Lt BTC Diskusijos: http://www.traders.lt/forums.php?m=posts&q=1945
BitcoinMarkets Subreddit: https://reddit.com/r/bitcoinmarkets/

Keityklos:

Bittrex: https://bittrex.com/ (Populiariausias ir šiuo metu geriausias altcoins exchange, BTC/USDT)
Poloniex: https://poloniex.com/ (Altcoins exchange, BTC/USDT)
Bitfinex: https://www.bitfinex.com/ (Didžiausias BTC/USD Volume)
Bitstamp: https://www.bitstamp.net/ (Yra BTC/EUR, SEPA pervedimai)
Kraken: https://www.kraken.com/ (Yra BTC/EUR, SEPA pervedimai)


Telefoniniai Appsai:

Blockfolio (iOS/Android) - Sekti portfolio/kainas
Tradingview (iOS) - Sekti kainas/grafikus
TabTrader (iOS/Android) - Exchange API trading(edited)

Kur galima tiesiogiai pirkti bitcoin/ltc
http://bittybot.co/uk/ - GBP
https://www.bitstamp.net/ - paypal
https://blockchain.info/ - kreditinės kortelės

Kiti:
Kripto žemėlapis - http://cryptomaps.org/
Bitcoin resursai - https://lopp.net/bitcoin.html
Tumblebit - Anonimizuotas bitcoin siuntimas.
xapo.com - Bitcoin kreditinė mokėjimo kortelė

Heroku

prerequisites 

$ pip install pipenv

$ git clone https://github.com/heroku/python-getting-started.git && cd python-getting-started

$ heroku create

$ git push heroku master

$ heroku ps:scale web=1

$ heroku open

Logs:

$ heroku logs --tail

Cloning existing app:


$ heroku apps
$ heroku git:clone -a myapp



Create a new Git repository

Initialize a git repository in a new or existing directory

$ cd my-project/
$ git init
$ heroku git:remote -a repository-name

$ git add .
$ git commit -am "make it better"
$ git push heroku master
Existing Git repository

For existing repositories, simply add the heroku remote
$ heroku git:remote -a flask-de


Heroku remote example:
https://git.heroku.com/flask-app.git 

Required files

Heroku app requires Procfile:
web: gunicorn app:app

Requirements.txt
gunicorn==19.6.0

Access website from:
https://flask-app.herokuapp.com/

2017 m. spalio 21 d., šeštadienis

python decorators

1. Simple decorator:

def decorator_function(passed_method):
    def returns_method():
        print("Decorating function: {}".format(passed_method.__name__))
        return passed_method()

    return returns_method


def speak():
    print("01101")


speak = decorator_function(speak)
speak()


Is same as:

def decorator_function(passed_method):
    def returns_method():
        print("Decorating function: {}".format(passed_method.__name__))
        return passed_method()

    return returns_method


@decorator_function
def speak():
    print("01101")

speak()


Output:
Decorating function: speak 
01101

1.2 Decoration with arguments:

def decorator_function(passed_method):
    def returns_method(*args, **kwargs):
        print("Decorating function: {}".format(passed_method.__name__))
        return passed_method(*args, **kwargs)

    return returns_method


@decorator_function
def speak(word):
    print(word)


@decorator_function
def say(argument):
    print(argument)


speak("Hello")
say("World is round")

Output:
Hello
Decorating function: say
World is round

2. Example: get function time decorator:

def function_time(passed_method):
    import time

    def returns_method(*args, **kwargs):
        t1 = time.time()
        result = passed_method(*args, **kwargs)
        time_span = time.time() - t1
        print("Function: {}, Time: {}".format(passed_method.__name__, time_span))

        return result

    return returns_method


@function_time
def process():
    return [x for x in range(10000)]


process()
Output:
Function: process, Time: 0.0006840229034423828

2017 m. spalio 19 d., ketvirtadienis

2017 m. spalio 18 d., trečiadienis

apt failed to fetch sources or download failed

Problem:
E: Failed to fetch http://repo.steampowered.com/steam/dists/precise/InRelease Unable to find expected entry 'steam/source/Sources' in Release file (Wrong sources.list entry or malformed file)

E: Some index files failed to download. They have been ignored, or old ones used instead.


Solution:

Go to:
$ cd /etc/apt/sources.list.d

And remove:
$ sudo rm steam.list

Problem:
Oracle JDK 6 is NOT installed.
dpkg: error processing package oracle-java6-installer (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 oracle-java6-installer

E: Sub-process /usr/bin/dpkg returned an error code (1)

Solution:

$ sudo apt-get remove --purge  oracle-java6-installer

2017 m. spalio 15 d., sekmadienis

Microsoft SQL Server + pymssql

The default SQL port is 1433.

Linux install Microsoft SQL Server and tools here:
$ sqlcmd -S localhost -U SA -P password

Script location

/opt/mssql-tools/bin/sqlcmd
/opt/mssql-tools/bin/bcp

Some interesting SQL commands:

SELECT GETDATE()
2017-10-21 22:36:52.08

System catalog tables

SYSUSERS -  Database users
SYS.DATABASES  - All database segments
SYS.DATABASE_PERMISSIONS - All database permissions
SYS.DATABASE_FILES - All database files
SYSINDEXES - All indexes
SYSCONSTRAINTS - All constraints
SYS.TABLES - All database tables
SYS.VIEWS - All database views

Query's:

# Show all database
Select * from Sys.Databases

# Delete database from database
DROP DATABASE Database_name;

Python lib to connect to Microsoft SQL Server pymssql.

Connecting to database:

import pymssql
server = "localhost"
user = "SA"
password = "password"

conn = pymssql.connect(server, user, password, "TestDB")
cursor = conn.cursor()

Show all tables:
cursor.execute("SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'")
for row in cursor:
    print("{}".format(row))

Get all table Inventory values:

cursor.execute("SELECT * FROM Inventory")
for row in cursor:
    print("{}".format(row))
conn.close()


Create table:

cursor.execute("""CREATE TABLE books (
               id INT NOT NULL,
               book_name VARCHAR(100),
               year VARCHAR(100),
               PRIMARY KEY(id)
               )
               """)
conn.commit()

Add entry to  to table:

cursor.execute("INSERT INTO books VALUES (1,'Freedom from known', 1955)")
con.commit()

2017 m. spalio 14 d., šeštadienis

SOAP and WSDL

SOAP originally stood for Simple Object Access Protocol, but it is no longer restricted in any way to object access or object-oriented use. Starting with version 1.2, the acronym is no longer officially spelled out; that is, "SOAP" is just a name. Although it originated from an industrial consortium, the XML Protocol Working Group of the W3C now has change control for new versions of SOAP. Here we give an overview of the features that SOAP includes and excludes, examine its relationship to XML, and list the basic SOAP namespaces.


The SOAP 1.1 specification required all services to use a SOAPAction header.

SOAP Faults
SOAP nodes return error or status information to a node from which they have received a message. They send back a SOAP message with a Body Block consisting of the Fault element in the soap-envelope namespace. Fault has two mandatory child elements, "faultcode" and "faultstring," and two optional child elements, "faultactor" and "detail."
  • The "faultstring" element has text content that is intended to be a human-readable explanation.
  • The "faultactor" element (fault actor) has a URI as its content to identify the actor at which the Fault occurred. It is optional only for ultimate receivers. All intermediate nodes generating a Fault element must provide a "faultactor" in any such Fault.
  • The "detail" element provides application-dependent additional information on a Fault generated by processing a message Body. You should not include this element for Header Block errors. Rather, the application must include it if the Body contents could not be processed successfully. Its presence indicates that the ultimate receiver at least processed some of the Body. The content and attributes of the "detail" element are application dependent. It can have an "encodingStyle" attribute. All element children of a "detail" element are called detail entries.
  • The "faultcode" element contains a namespace-qualified name.

Header:
The Header element namespace serves as a container for extensions to SOAP.
No extensions are defined by the specification, but user-defined extension ser-
vices such as transaction support, locale information, authentication, digital sig-
natures, and so forth could all be implemented by placing some information inside
the Header element. Children of the Header element may be annotated with the
mustUnderstand and/or actor attributes.

SOAP HTTP binding
SOAP defines a binding to the HTTP protocol. This binding describes the relation-
ship between parts of the SOAP request message and various HTTP headers. All
SOAP requests use the HTTP POST method and specify at least three HTTP head-
ers: Content-Type, Content-Length, and a custom header SOAPAction.
The actual SOAP message is passed as the body of the request or response.

Content-Type
Content-Type: text/xml; charset=character encoding
The Content-Type header for SOAP requests and responses specifies the
MIME type for the message and is always text/xml. It may also specify the
character encoding used for the XML body of the HTTP request or response. This
follows the text/xml part of the header values.


WSDL

 WSDL - Web Services Description Language .

WSDL provides a way of describing how to make request to SOAP service.

 A programmer would use WSDL to figure out what procedures are available from the SOAP server and what format of XML is expected by that procedure, and then write the code to call it.


The first task in a WSDL file is to define the information that will be sent to and from the service. A WSDL file builds the service up in levels. First, it defines the data to be sent and received, and then it uses that data to define messages.



SQL - Structured Query Language

The main categories are:
  • Data Definition Language (DDL) 
  • Data Manipulation Language (DML) - INSERT, UPDATE, DELETE 
  • Data Query Language (DQL) - SELECT 
  • Data Control Language (DCL) 
  • Data administration commands 
    • Transactional control commands 
    • COMMIT—Saves database transactions 
    • ROLLBACK—Undoes database transactions 
    • SAVEPOINT—Creates points within groups of transactions in which to 
    • ROLLBACK 
    • SET TRANSACTION—Places a name on a transaction

Very basic data types:
  • String types
  • Numeric types
    • BIT
    • DECIMAL
    • INTEGER
    • SMALLINT
    • BIGINT
    • FLOAT
    • DOABLE PRECISION
    • REAL
  • Date and time types
    •  DATE
    •  TIME
    •  DATETIME
    •  TIMESTAMP
  • Literal Strings
  • NULL

When using the NULL data type, it is important to realize that data is not required in a particular field. If data is always required for a given field,


Definitions
Acronyms:

Database Management system (DBMS)
Relational database management system (RDBMS)
Structured Query Language (SQL) 
American National Standards Institute (ANSI)

Open Database Connectivity (ODBC) 
JDBC is Java Database Connectivity (DBC)
Definitions:

Database is a collection of data.
Data is a collection of information stored in a database as one of several different data types.


A relational database is a database divided into logical units called tables, where tables are related to one another within the database.


A database object is any defined object in a database that is used to store or reference data.(tables, views, clusters, sequences, indexes, and synonyms)

A schema is a collection of database objects normally associated with one particular database username.

A transaction is a unit of work that is performed against a database accomplished using the Data Manipulation Language (DML) commands.
the transaction.

Three commands are used to control transactions:
  • COMMIT
  • ROLLBACK
  • SAVEPOINT

An aggregate
Function provides summarization information for an SQL statement, such as counts, totals, and averages.
  • COUNT
  • SUM
  • MAX/MIN
  • AVG
Character functions are functions that represent strings in SQL in formats different from the way they are stored in the table. 

Concatenation is the process of combining two strings into one. 

A subquery, also known as a nested query, is a query embedded within the WHERE clause of another query to further restrict data returned by the query.

Single query is one SELECT statement
Compound query includes two or more SELECT statements.

Index is a pointer to data in a table. (Like book index).

  • Single-Column Indexes
  • Unique Indexes
  • Composite Indexes
  • Implicit Indexes

SQL statement tuning is the process of optimally building SQL statements to achieve results in the most effective and efficient manner.

A trigger is a compiled SQL procedure in the database that performs actions based on other actions occurring within the database. 
Dynamic SQL allows a programmer or end user to create an SQL statement’s specifics at runtime and pass the statement to the database. 


2017 m. spalio 5 d., ketvirtadienis

xpath

XPath defines two terms—context node-set and context node— to help describe
how the location path evaluation process works. The context node-set is
defined as the current set of nodes that has been identified up to a given point in
the expression. The context node is defined as the current node being processed.


XPath defines several abbreviations 


XPath supports standard and/or boolean expressions. Each operand is evalu-
ated and coerced to a boolean (as if by calling the boolean function) before
evaluation.
To select an attribute using unabbreviated syntax, we can write the following:
attribute:: attributename
Or, in the abbreviated form, simply write the following:
@attributename


xpath="author"
Selects the child elements named author that do not belong to any namespace.

xpath="author|character"
Selects the child elements named author or character that do not belong to any
namespace.
xpath="lib:author"
Selects the child elements named author that belong to the namespace whose
prefix is "lib".
xpath="*"
Selects all the child elements.
xpath="lib:*"
Selects all the child elements that belong to the namespace whose prefix is "lib".
xpath="authors/author"
Selects all the authors/author child elements.
xpath=".//author"
Selects all the elements that are descendants of the current node, named author,
and don't belong to any namespace.
xpath="author/@id"
Selects the id attribute of the author child element (allowed only for xs:field,
and not for xs:selector).
xpath="@id|@name"
Selects @id or @name (valid only in xs:field, since attributes are forbidden in
xs:selector).
The following are forbidden:
xpath="/library/author"
Absolute paths are not allowed.
xpath="../author"
The parent axis is not allowed.

2017 m. rugsėjo 28 d., ketvirtadienis

xml

James Clark invented the name Extensible Markup Language and its abbreviation XML. He has been quoted as saying, "XML isn't going to win any prizes for technical elegance. But it was just simple enough that it could get broad acceptance, and it has just enough Standard Generalized Markup Language (SGML) stuff in it that the SGML community felt they could embrace it." (SGML is a standard indicating how to specify a document language or tag set.)


The XML Recommendation defines a methodology for tag creation. It specifies neither tag semantics nor a specific tag set. That is, XML specifies structure, not meaning. You can define an infinite number of markup languages based on the XML Recommendation standards.


Once defined, tags are mixed with character data to form an "XML document." An XML document can take numerous forms. For example, it can be a logical structure within a computer program or an external file in the traditional sense. Likewise, an XML document can be sent as a data stream, reported as a database result set, or dynamically generated by one application and sent to another.

 XML is case sensitive.

Elements and tags

Element;
<Today> Breaking news </Today>

Tag
<Today>

Also closed tag:
<Today/>

Atribute
An attribute is a property of an element.
The attribute includes both the name and the value.
<Today answer="42">Some info</Today>

Well-Formed 
  •  Every start-tag must have a matching end-tag, or be a self-closing tag.
  •  Tags can’t overlap; elements must be properly nested.
  •  XML documents can have only one root element.
  •  Element names must obey XML naming conventions.
  •  XML is case sensitive.
  •  XML will keep whitespace in your PCDATA.

Well-formedness is the minimum requirement necessary for an XML document. It includes various syntactic constraints, such as every start-tag must have a matching end-tag and the document must have exactly one root element. If a document is not well formed, it is not an XML document. Parsers that encounter a malformed document are required to report the error and stop parsing.

XML Declaration
The following are all legal XML declarations.

<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<?xml version="1.0" standalone="yes"?>

Each XML declaration has up to three attributes.

  • version*: the version of XML in use. Currently this always has the value 1.0, though there may be an XML 1.1 in the future. 
  • encoding (optional): the character set in which the document is written.
  • standalone (optional): whether or not the external DTD subset makes important contributions to the document's infoset. No is the default.
    • yes specifies that this document exists entirely on its own, without depending on any other files.
    • no indicates that the document may depend on an external DTD (DTDs are covered in Chapter 4).
System Identifier
<? Some instruction ?>

DTD - Document Type Definitions
<!DOCTYPE name [
<!ELEMENT name (first, middle, last)>
<!ELEMENT first (#PCDATA)>
<!ELEMENT middle (#PCDATA)>
<!ELEMENT last (#PCDATA)>
]>

CDATA
Everything starting after the <![CDATA[ and ending at the ]]> is ignored by the parser.

XMLNamespaces
The key is the xmlns:ppp attribute (xmlns stands for XML NameSpace).

We can declare more than one namespace for an element, but only one can be the default.

Immediately following the XML header is the Document Type Declaration,
<!DOCTYPE name [

Built-In Entities
&amp;—the & character
&lt;—the < character
&gt;—the > character
&apos;—the ' character
&quot;—the " character

XML Schemas

W3C XML Sc allow you to describe the structure for an XML document. 

XML Schema divides data types into two broad categories: simple and complex.

Examples:
<schema xmlns="http://www.w3.org/2001/XMLSchema">
or
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
or
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">



Definitions:

Markup
The term  has its origins in the publishing industry. In traditional publishing, markup happens after the writing is complete but before the book goes to typesetting. An editor annotates the text with handwritten instructions for the typesetter. These instructions, which specify the layout, are known as markup. Many contemporary word processing programs insert electronic markup automatically as the user creates the text.

XML 
Is an open-specification, platform-independent, extensible, and increasingly successful profile of the Standard Generalized Markup Language (SGML) [ISO 8879].


Well-Formed Documents"Well formed" has an exact meaning in XML. A well-formed document adheres to the syntax rules specified by the XML 1.0 Recommendation. . If the document is not well-formed and an error appears in the XML syntax, the XML processor stops and reports the presence of a fatal error.

DTD
Document Type Definitions (DTDs) are important in data exchange. Parties exchanging data must agree on a format, and a DTD allows the specification of that format.

The DTD defines the grammar and vocabulary of a markup language, specifying what is and what is not allowed to appear in a document—for example, which tags can appear in the document and how they must nest within one another.

This grammar is known as a Document Type Definition. A DTD defines the allowable building blocks of an XML document; that is, it defines the document structure with a list of permissible elements, attributes, nestings, and so on.
<?xml version="1.0"?><!DOCTYPE memo SYSTEM "memo.dtd">

The term "PCDATA," which stands for "Parsed Character DATA,"

CDATA
CDATA is text that will notbe analyzed by a parser, except to look for the magic CDATA termination string
<![CDATA[<greeting>Hello, world!</greeting>]]>

Namespaces
The intent of XML namespaces is to eliminate naming conflicts in XML documents that contain element types and attributes from multiple XML languages.
<?xml version="1.0"?><name xmlns:family='http://mypage.com/classification'>
  • The prefix "xmlns" is used only for namespace bindings and is not itself bound to any namespace name.

The Extensible Stylesheet Language (XSL)
W3C Recommendation [XSL] defines the XSL language for expressing stylesheets. XSL builds on the prior work on Cascading Style Sheets Level 1 [CSS1] and Level 2 [CSS2] and the Document Style Semantics and Specification Language [ISO 10179].

XSL was developed to give designers greater control over needed features during pagination of documents and to provide an equivalent "frame"-based structure for browsing on the Web. It also incorporates the use of the XLink language [Xlink] to insert elements into XML documents that create and describe links between resources.

XML Schema 
A schema is a model for describing the structure of information.
XML Schema is a way of describing the allowable syntax of XML
xmlns:xs="htp://www.w3.org/2001/XMLSchema"

An XML processor
Is more commonly called a parser.

PCDATA
Parsed Character DATA,

whitespace
Space character, new lines (what you get when you hit the Enter key), and tabs.
XML elements are treated just as for the HTML <PRE> tag.
 “readability” whitespace is called extraneous whitespace, which whitespace is not actually part of an element’s PCDATA,

A URI (Uniform Resource Identifier) 
  • URL (Uniform Resource Locator)
  • URN (Uniform Resource Name)
    • They exist to provide a persistent, location example: urn:foo:a123,456

Resources:

XML formater without validation - http://www.webtoolkitonline.com/xml-formatter.html

Scrum story points

Story points:

1 story point = 30 min
2 story point = 1 h

16 story point = 8 h

16 story point = 8 h = one day
48 story point = 8 h for 3 day
80 story point = 8 h for 5 days

Python libraries libxml2 and pyXMLSec for Digital Signature

Here is one ancient library, so yes, let's work with this libraries. Asking why, well.
Business, business, business, numbers.


libxml2


>>> doc = libxml2.parseDoc(xml_file) # Parsing file
>>> doc = libxml2.parseFile(xml_file)  # Parsing html

Node itteration
All nodes:
>>> ctxt = doc.xpathNewContext() 
>>> ctxt.xpathEval('//*')
[<xmlNode (Envelope) object at 0x7f55b8a329e0>, ...]

>>> for node in ctxt.xpathEval('//*'): print(node.name)
Envelope
Header
Body
deliverSecure
...

def serialize(self, encoding=None, format=0)
>>> xml = doc.serialize()

Creating nodes

>>> print(libxml2.newNode("Security"))
<Security/>


findChild(parent, name, ns=None)
Searches a direct child of the parent node having given name and namespace


<Sender>
<Id>42</Id>
<Name>Really good name</Name>
</Sender>


Creating namespace:
>>> nswsse = sec.newNs('http://test.xsd', 'wsse')

>>> print(nswsse)
 xmlns:wsse="http://test.xsd"
>>> sec.setNs(nswsse)

>>> print(sec)
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"/>

Adding attribute:
>>> sec.setProp("id", "900")
<xmlAttr (id) object at 0x7f30b8cc3638>
>>> print(sec)
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" id="900"/>


pyXMLSec

createTree
Creates a new XML tree with one root node rootNodeName.


>>> tets = xmlsec.createTree("test", "aa")
>>> print(tets)
<?xml version="1.0"?>
<test xmlns="aa"/>


findNode(parent, name, ns=None)
Searches all children of the parent node having given name and namespace href.

>>> find_node = xmlsec.findChild(doc, "Name")
>>> find_node.get_content()
'Really good name'

Information about element:

>>> xml_doc.getRootElement()

<xmlNode (Envelope) object at 0x7ffa545bfab8>



>>> xml_doc.getRootElement().nodePath()

'/soapenv:Envelope'

>>> xml_doc.nodePath()

'/'



>>> xml_doc.get_type()
'document_xml' or 'element'

>>> sign_node.get_name()
'Signature'

Variables:
>>> xmlsec.DSigNs
'http://www.w3.org/2000/09/xmldsig#'




Creating signature:

>>> signNode = xmlsec.TmplSignature(xml_doc, xmlsec.transformExclC14NId(), xmlsec.transformRsaSha1Id(), None)

>>> signNode.__str__()
'<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">\n<SignedInfo>\n<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>\n<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>\n</SignedInfo>\n<SignatureValue/>\n</Signature>'

>>> xmlsec.NodeSignature

'Signature'




Add reference:

>>> ref_node = signNode.addReference(xmlsec.transformSha1Id(), id=None, uri="", type=None)
>>> print(ref_node)
<Reference URI="">
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue/>
</Reference>




Finding elements:



>>> xmlsec.findNode(xml_doc.getRootElement(), "Header", "http://website.com/schema/Method" )
<xmlNode (Header) object at 0x7f4e9804f710>





keyDataAesId()
The AES key data id.

keyDataX509Id()
The X509 key data id.

keyDataXmlWrite(id, key, node, keyInfoCtx)
Writes the key data of klass id from key to an XML node.

keyInfoNodeRead(keyInfoNode, key, keyInfoCtx)
Parses the <dsig:KeyInfo/> element keyInfoNode, extracts the key data and
stores into key.

keyInfoNodeWrite(keyInfoNode, key, keyInfoCtx)
Writes the key into the <dsig:KeyInfo/> element template keyInfoNode.

Resources:

libxml2

libxml2 tutorial - https://www.xml.com/pub/a/2003/05/14/py-xml.html
TODO:tocheck parsing file with libxml2 example -  https://www.programcreek.com/python/example/8012/libxml2.parseFile
Documentation - http://xmlsoft.org/python.html

pyXMLSec