
Terminal - Commands tagged python - 46 results
python -c 'import sys, yaml, json; yaml.dump(json.load(sys.stdin), sys.stdout, default_flow_style=False)' < file.json > file.yaml
This is sample output - yours may be different.
Convert JSON to YAML.
Note that you'll need to have PyYaml installed.
python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < file.yaml > file.json
This is sample output - yours may be different.
Converts YAML file to JSON.
Note that you'll need to install PyYAML. Also some YAML data types (like dates) are not supported by JSON).
pygmentize -l pytb myapp.log | less -SR
This is sample output - yours may be different.
grep --color=always -nr 'setLevel' --include=*py | less -SRqg
This is sample output - yours may be different.
curl -L -d "uid=<username>&pwd=<password>" http://www.example.com -c cookies.txt
This is sample output - yours may be different.
Generate a Netscape cookies file to use with Python's mechanize.
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 18 | head -1 | python -c "import sys,crypt; stdin=sys.stdin.readline().rstrip('\n'); print stdin;print crypt.crypt(stdin)"
This is sample output - yours may be different.
NH6wAL58sKSkqBNUwK
$6$6ZpaL7bakRyXzrpM$TVS4d217.BDjKLEnYkPBtpR8CwXes5HI6U2pcSEoB3x9xUbXVxacEhvlvKFCi4tftwxOJs.Comh7u.GiPvA6X1
Generate a 18 character password from character set a-zA-Z0-9 from /dev/urandom, pipe the output to Python which prints the password on standard out and in crypt sha512 form.
alias colortest="python -c \"print('\n'.join([(' '.join([('\033[38;5;' + str((i + j)) + 'm' + str((i + j)).ljust(5) + '\033[0m') if i + j < 256 else '' for j in range(10)])) for i in range(0, 256, 10)]))\""
This is sample output - yours may be different.
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49
50 51 52 53 54 55 56 57 58 59
60 61 62 63 64 65 66 67 68 69
70 71 72 73 74 75 76 77 78 79
80 81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98 99
100 101 102 103 104 105 106 107 108 109
110 111 112 113 114 115 116 117 118 119
120 121 122 123 124 125 126 127 128 129
130 131 132 133 134 135 136 137 138 139
140 141 142 143 144 145 146 147 148 149
150 151 152 153 154 155 156 157 158 159
160 161 162 163 164 165 166 167 168 169
170 171 172 173 174 175 176 177 178 179
180 181 182 183 184 185 186 187 188 189
190 191 192 193 194 195 196 197 198 199
200 201 202 203 204 205 206 207 208 209
210 211 212 213 214 215 216 217 218 219
220 221 222 223 224 225 226 227 228 229
230 231 232 233 234 235 236 237 238 239
240 241 242 243 244 245 246 247 248 249
250 251 252 253 254 255
Terminal Color tester using python, works with py2 and 3
This is sample output - yours may be different.
colortest-python -h
Usage: colortest-python [options]
Options:
-b, --block Display as block format (vs cube) [default].
-c, --cube-slice Display as cube slices (vs block).
-l, --rgb Long format. RGB values as text.
-n, --numbers Include color escape numbers on chart.
-p, --padding Add extra padding (helps discern colors).
-v, --vertical Display with vertical orientation [default].
-x, --hex Include hex color numbers on chart.
-z, --horizontal Display with horizontal orientation.
--version show program's version number and exit
-h, --help show this help message and exit
Conversion options:
-r N, --256to88=N Convert (reduce) 256 color value N to an 88 color
value.
-e N, --88to256=N Convert (expand) 88 color value N to an 256 color
value.
Pre-packaged python script that comes with Debian/Ubuntu.
alias pp='python -mjson.tool | pygmentize -l javascript'
This is sample output - yours may be different.
curl -s http://www.reddit.com/.json | pp
Uses pygmentize and python to create indented and colorized JSON output
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
This is sample output - yours may be different.
Sample USAGE: f = open(os.path.join(__location__, 'bundled-resource.jpg'));
import unicodedata; map(unicodedata.name, '\u2022'.decode('ascii'))
This is sample output - yours may be different.
>>> print '\u2022'
\u2022
>>> print len('\u2022')
6
>>> import unicodedata
>>> map(unicodedata.name, '\u2022'.decode('ascii'))
['REVERSE SOLIDUS', 'LATIN SMALL LETTER U', 'DIGIT TWO', 'DIGIT ZERO', 'DIGIT TWO', 'DIGIT TWO']
>>> print u'\u2022'
?
>>> print len(u'\u2022')
1
>>> map(unicodedata.name, u'\u2022')
['BULLET']
vs. map(unicodedata.name, u'\u2022')
python -c 'import googl; print googl.Googl("<your_google_api_key>").shorten("'$someurl'")[u"id"]'
This is sample output - yours may be different.
$ python -c 'import googl; print googl.Googl("<your_google_api_key").shorten("'http://commandlinefu.com/'")[u"id"]'
http://goo.gl/zYAip
(1) required: python-googl ( install by: pip install python-googl )
(2) get from google API console https://code.google.com/apis/console/
tail -F /var/log/nginx/access.log | python -c 'exec("import sys,time\nl=0\ne=int(time.time())\nfor line in sys.stdin:\n\tt = int(time.time())\n\tl += 1\n\tif t > e:\n\t\te = t\n\t\tprint l\n\t\tl = 0")'
This is sample output - yours may be different.
27
49
36
36
29
33
33
32
43
31
40
35
43
39
37
38
28
34
31
48
46
37
35
Realtime lines per second in a log file using python ... identical to perl version, except python is much better :)
This is sample output - yours may be different.
for i in $(seq 1 20); do while read line; do echo "$i: $line"; done<$i.py; done
This is sample output - yours may be different.
python -c 'print "hello".encode("hex")'
This is sample output - yours may be different.
You can use "decode()" in a similar manner:
python -c 'print "68656c6c6f".decode("hex")'
python -c 'print hex(1337)'
This is sample output - yours may be different.
Python is always such much more readable than most shell scripting.
This is sample output - yours may be different.
Serving HTTP on 0.0.0.0 port 8000 ...
python -c 'import string, random; print "".join(random.choice(string.letters+string.digits) for x in range(6))'
This is sample output - yours may be different.
echo '{"json":"obj"}' | python -mjson.tool
This is sample output - yours may be different.
calc() { echo "scale=4; ${*//,/.}" | bc -l; }
This is sample output - yours may be different.
This is an "argument calculator" funktion. The precision is set to 4 and you can use dot (.) or comma (,) as decimal mark (which is great for german users with a comma on the numpad).
python -ic "from __future__ import division; from math import *; from random import *"
This is sample output - yours may be different.
This opens a python command line. You can use math and random and float-division is enabled (without appending .0 to integers). I just don't know how to specify a standard precision.
alias calc='python -ic "from math import *; from random import *"'
This is sample output - yours may be different.
$ calc
>>> 22.0/7
3.1428571428571428
>>> 22/7.0
3.1428571428571428
>>>
use python as calculator, press ctrl+d to exit
reminder: when doing factions add atleast one decimal number like so
22.0/7 or 22/7.0
python -c 'p="SeCuR3PwD";import hashlib as h;s=h.md5(p).hexdigest()[:2];pw=h.md5(s+p).hexdigest();print pw+":"+s;'
This is sample output - yours may be different.
fcb35a57bb4a6a17063fab56fad93138:23
ZenCart uses a MD5 with a salt to secure its passwords. If you need to forcibly change someone's password to a known value within the database, this one-liner can generate the password. Change the value of 'p' to the password you want.
python -c'for i in range(1,101):print"FizzBuzz"[i*i%3*4:8--i**4%5]or i'
This is sample output - yours may be different.
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz
A common programming question for interviewers to ask potential job candidates is to code "FizzBuzz". That is, if a number is divisible by 3, then it should display "Fizz". If a number is divisible by 5, it should display "Buzz". If it is divisible by both, then it should display "FizzBuzz". Otherwise, display the current number between 1 and 100.