sobota, 31 sierpnia 2013

python and mysql

#!/usr/bin/python

import MySQLdb as mdb

con = mdb.connect('localhost', 'root', 'password', 'baza');

with con:

        cur = con.cursor()
        cur.execute("INSERT INTO adresy(imie,nazwisko) VALUES('Marek', 'Borkowski')")

        cur.execute("Select * from baza.adresy")
        for row in cur.fetchall():
                id = str(row[0])
                imie = str(row[1])
                nazwisko = str(row[2])

                print "id: ",id
                print "imie: ",imie
                print "nazwisko: ",nazwisko
                print "--------"
        cur.close()

czwartek, 29 sierpnia 2013

very simple mathematics

#!/usr/bin/python

for i in range(1, 10):
        for j in range(1, 10):
                iloczyn = i*j
                print ('i wynosi: ',i)
                print ('j wynosi: ',j)
                print iloczyn

niedziela, 25 sierpnia 2013

User-defined Exceptions in Python

#!/usr/bin/pypy

try:
        fo = open("/tmp/foo.txt", "wb")
        fo.write ("Marek Borkowski \n")
        if True:
                print 'ok'
        fo.close()
except IOError:
        print 'Something goes wrong'


and more advanced:

#!/usr/bin/pypy
import sys
total = len(sys.argv)

if len(sys.argv) > 1:
        try:
                fo = open(sys.argv[1], "wb")
                fo.write ("Marek Borkowski \n")
                if True:
                        print 'ok'
                fo.close()
        except IOError:
                print 'Something goes wrong'
else:
        print '

python philosophy

marek::lati { ~/Dokumenty/python }-> python
Python 2.7.3 (default, Apr 10 2013, 06:20:15)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

sobota, 17 sierpnia 2013

swiss army knife - netcat.

1. file transfer

root::lati { ~ }-> nc -v -l 81 < test.txt
Connection from 127.0.0.1 port 81 [tcp/*] accepted
GET / HTTP/1.1
User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
Host: localhost:81
Accept: */*


other site/terminal:

root::lati { ~ }-> wget localhost:81
--2013-08-17 21:50:09--  http://localhost:81/
Translacja localhost (localhost)... 127.0.0.1
Łączenie się z localhost (localhost)|127.0.0.1|:81... połączono.
Żądanie HTTP wysłano, oczekiwanie na odpowiedź... Brak danych w odpowiedzi.
Ponawianie próby.

--2013-08-17 21:50:10--  (próba: 2)  http://localhost:81/
Łączenie się z localhost (localhost)|127.0.0.1|:81... nieudane: Połączenie odrzucone.
Translacja localhost (localhost)... 127.0.0.1
Łączenie się z localhost (localhost)|127.0.0.1|:81... nieudane: Połączenie odrzucone.
(you can ignore all error in this case)

root::lati { ~ }-> ll
razem 0
-rw-r--r-- 1 root root 0 sie 17 21:34 test.tx

poniedziałek, 12 sierpnia 2013

adb monitoring commands

1. adb shell dumpsys battery

root@ubu:~# adb shell dumpsys battery
Current Battery Service state:
  AC powered: false
  USB powered: true
  Wireless powered: false
  status: 2
  health: 2
  present: true
  level: 83
  scale: 100
  voltage:4193
  temperature: 297
  technology: Li-ion


2. adb shell dumpsys wifi - to wide to publicate :)

3. adb shell dumpsys cpuinfo
root@ubu:~# adb shell dumpsys cpuinfo
Load: 0.69 / 0.35 / 0.52
CPU usage from 9881ms to 2399ms ago with 99% awake:
  1.6% 523/system_server: 0.6% user + 0.9% kernel / faults: 53 minor
  0.4% 29973/com.android.providers.calendar: 0.4% user + 0% kernel / faults: 12 minor
  0.2% 183/mpdecision: 0% user + 0.2% kernel
  0.2% 1511/com.google.android.calendar: 0.2% user + 0% kernel / faults: 11 minor
  0% 152/jbd2/mmcblk0p23: 0% user + 0% kernel
  0% 634/com.android.systemui: 0% user + 0% kernel
  0.1% 7488/kworker/0:3: 0% user + 0.1% kernel
  0% 28295/kworker/0:5: 0% user + 0% kernel
  0% 32376/kworker/0:1: 0% user + 0% kernel
2.8% TOTAL: 1.6% user + 0.8% kernel + 0.4% iowait


4. adb shell dumpsys meminfo


root@ubu:~# adb shell dumpsys cpuinfo
Load: 0.69 / 0.35 / 0.52
CPU usage from 9881ms to 2399ms ago with 99% awake:
  1.6% 523/system_server: 0.6% user + 0.9% kernel / faults: 53 minor
  0.4% 29973/com.android.providers.calendar: 0.4% user + 0% kernel / faults: 12 minor
  0.2% 183/mpdecision: 0% user + 0.2% kernel
  0.2% 1511/com.google.android.calendar: 0.2% user + 0% kernel / faults: 11 minor
  0% 152/jbd2/mmcblk0p23: 0% user + 0% kernel
  0% 634/com.android.systemui: 0% user + 0% kernel
  0.1% 7488/kworker/0:3: 0% user + 0.1% kernel
  0% 28295/kworker/0:5: 0% user + 0% kernel
  0% 32376/kworker/0:1: 0% user + 0% kernel
2.8% TOTAL: 1.6% user + 0.8% kernel + 0.4% iowait
root@ubu:~#
root@ubu:~#
root@ubu:~#
root@ubu:~#
root@ubu:~# adb shell dumpsys meminfo
Applications Memory Usage (kB):
Uptime: 37179113 Realtime: 88324695

Total PSS by process:
    86097 kB: com.android.chrome (pid 4767)
    67054 kB: system (pid 523)
    44244 kB: com.android.launcher (pid 800)
    44235 kB: com.android.systemui (pid 634)
    36618 kB: com.facebook.katana (pid 30545)
    31162 kB: com.google.android.googlequicksearchbox (pid 5048)
    27171 kB: com.android.chrome:sandboxed_process3 (pid 12512)
    25688 kB: com.facebook.orca (pid 27691)
    22199 kB: com.google.android.inputmethod.latin (pid 719)
    19538 kB: com.google.android.apps.plus (pid 5355)
    19059 kB: com.android.phone (pid 774)
    17500 kB: com.android.dialer (pid 17592)
    16791 kB: com.facebook.katana:dash (pid 8465)
    12976 kB: com.google.android.gms (pid 2245)
    12791 kB: com.google.process.location (pid 757)
    12684 kB: com.google.process.gapps (pid 844)
    12185 kB: com.twitter.android (pid 8198)
    11349 kB: com.google.android.talk (pid 6276)
    10067 kB: android.process.acore (pid 15669)
     8282 kB: com.google.android.youtube (pid 8099)
     7782 kB: com.google.android.music:main (pid 7629)
     7755 kB: com.sand.airdroid:push (pid 827)
     7555 kB: com.android.vending (pid 8302)
     7066 kB: com.google.android.gallery3d (pid 6834)
     6916 kB: com.google.android.calendar (pid 1511)
     5884 kB: android.process.media (pid 2703)
     5597 kB: com.android.mms (pid 8075)
     5068 kB: com.android.providers.calendar (pid 29973)
     4831 kB: com.android.nfc (pid 785)
     3740 kB: com.google.android.apps.uploader (pid 8062)
     3401 kB: com.google.android.deskclock (pid 8420)
     3145 kB: dev.ukanth.ufirewall (pid 8184)
     2843 kB: com.android.nfc:handover (pid 862)

Total PSS by OOM adjustment:
    67054 kB: System
               67054 kB: system (pid 523)
    68125 kB: Persistent
               44235 kB: com.android.systemui (pid 634)
               19059 kB: com.android.phone (pid 774)
                4831 kB: com.android.nfc (pid 785)
    61035 kB: Foreground
               44244 kB: com.android.launcher (pid 800)
               16791 kB: com.facebook.katana:dash (pid 8465)
    38385 kB: Visible
               12791 kB: com.google.process.location (pid 757)
               12684 kB: com.google.process.gapps (pid 844)
               10067 kB: android.process.acore (pid 15669)
                2843 kB: com.android.nfc:handover (pid 862)
    22199 kB: Perceptible
               22199 kB: com.google.android.inputmethod.latin (pid 719)
    20731 kB: A Services
               12976 kB: com.google.android.gms (pid 2245)
                7755 kB: com.sand.airdroid:push (pid 827)
    17500 kB: Previous
               17500 kB: com.android.dialer (pid 17592)
     7782 kB: B Services
                7782 kB: com.google.android.music:main (pid 7629)
   306462 kB: Background
               86097 kB: com.android.chrome (pid 4767)
               36618 kB: com.facebook.katana (pid 30545)
               31162 kB: com.google.android.googlequicksearchbox (pid 5048)
               27171 kB: com.android.chrome:sandboxed_process3 (pid 12512)
               25688 kB: com.facebook.orca (pid 27691)
               19538 kB: com.google.android.apps.plus (pid 5355)
               12185 kB: com.twitter.android (pid 8198)
               11349 kB: com.google.android.talk (pid 6276)
                8282 kB: com.google.android.youtube (pid 8099)
                7555 kB: com.android.vending (pid 8302)
                7066 kB: com.google.android.gallery3d (pid 6834)
                6916 kB: com.google.android.calendar (pid 1511)
                5884 kB: android.process.media (pid 2703)
                5597 kB: com.android.mms (pid 8075)
                5068 kB: com.android.providers.calendar (pid 29973)
                3740 kB: com.google.android.apps.uploader (pid 8062)
                3401 kB: com.google.android.deskclock (pid 8420)
                3145 kB: dev.ukanth.ufirewall (pid 8184)

Total PSS by category:
   254338 kB: Dalvik
   157642 kB: Unknown
    72263 kB: .dex mmap
    58141 kB: .so mmap
    37848 kB: Other dev
    19339 kB: .apk mmap
     6190 kB: Stack
     2865 kB: Other mmap
      431 kB: .ttf mmap
      122 kB: .jar mmap
       92 kB: Cursor
        2 kB: Ashmem
        0 kB: Native

Total PSS: 609273 kB
      KSM: 0 kB saved from shared 0 kB
           0 kB unshared; 0 kB volatile



5. adb shell dumpsys activity - to looong


sobota, 3 sierpnia 2013

rm in verbose mode

rm -rf * -vf

root@ubu:/tmp# rm -rf * -vf
usunięty „1”
usunięty „10”
usunięty „2”
usunięty „3”
usunięty „4”
usunięty „5”
usunięty „6”
usunięty „7”
usunięty „8”
usunięty „9”

-v, --verbose
              explain what is being done

for part2

for i in `seq 1 100`; do touch $i; done - create 101 files



for - way to do the same thing

for I in {1..10}; do echo $I; done

for I in 1 2 3 4 5 6 7 8 9 10; do echo $I; done

for I in $(seq 1 10); do echo $I; done

for ((I=1; I <= 10 ; I++)); do echo $I; done

piątek, 2 sierpnia 2013

apt-get update NO_PUBKEY error

if you have a problem with your apt in ubuntu

like:
Pobrano 348 kB w 21s (15,9 kB/s)
Czytanie list pakietów... Gotowe
W: Błąd GPG: http://download.opensuse.org  Release: Następujące podpisy nie mogły zostać zweryfikowane z powodu braku klucza publicznego: NO_PUBKEY 977C43A8BA684223


you should:

sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 977C43A8BA684223

czwartek, 1 sierpnia 2013

supersu for android 4.3

Start with nexus 4 rooting procedure:
1. wget http://techerrata.com/file/twrp2/mako/openrecovery-twrp-2.4.1.0-mako.img
2. fastboot flash recovery openrecovery-twrp-2.4.1.0-mako.img
sending 'recovery' (8294 KB)...
OKAY [ 0.520s]
writing 'recovery'...
OKAY [ 0.424s]
finished. total time: 0.945s
3. Since now when we start recovery mode we should have user friendly tool
4. restart boot loader
fastboot reboot-bootloader
rebooting into bootloader...
OKAY [ 0.001s]
finished. total time: 0.001s
5. download app for android 4.3 http://download.chainfire.eu/344/SuperSU/UPDATE-SuperSU-v1.50.zip
6. copy to mobile sd card or use adb:
adb push 'UPDATE-SuperSU-v1.50.zip' /sdcard/
7.  After you’ve flashed the superuser package, wipe cache and dalvik cache, just to be on the safe side.
8. Restart

After this 8 steps you should have root mode enabled in your nexus.


use adb to execute phone procedure

adb shell am start -a android.intent.action.CALL tel:5148888888

how to send sms from linux shell

1. add repo key
sudo add-apt-repository ppa:nilarimogard/webupd8
2. # sudo apt-get update
3. # sudo apt-get install android-tools-adb android-tools-fastboot

now when you type in command prompe bellowed command you can send sms from you terminal window, when you of course connect your pc with your mobile.

adb shell am start -a android.intent.action.SENDTO -d sms:728403930 --es sms_body "test" --ez exit_on_sent true

adb shell input keyevent 22
adb shell input keyevent 66