forked from xiaket/etc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snape.json
226 lines (226 loc) · 10.1 KB
/
snape.json
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
{
"HTTP request in bash": {
"content": "exec 3<> /dev/tcp/checkip.amazonaws.com/80\nprintf \"GET / HTTP/1.1\\r\\nHost: checkip.amazonaws.com\\r\\nConnection: close\\r\\n\\r\\n\" >&3\ntail -n1 <&3",
"lang": "Text only"
},
"UNIX time to datetime": {
"content": "from datetime import datetime\ndatetime.fromtimestamp(1409638930)",
"lang": "Python"
},
"Ubuntu add normal user": {
"content": "useradd -m -U -s /bin/bash $username",
"lang": "Bash"
},
"ansible keep remote files": {
"content": "export ANSIBLE_KEEP_REMOTE_FILES=1",
"lang": "Bash"
},
"awk average columns": {
"content": "awk '{ total += $1; count++} END {print total/count}' filename",
"lang": "Bash"
},
"awk delete line with pattern": {
"content": "echo $line\n/websites/webapps/Auski_Test/Auski_Test_log\ncat /etc/fstab | awk -v l=$line '{if($1!=l) print $0}'",
"lang": "Bash"
},
"awk print line if field not starts with": {
"content": "awk '$5 !~ /^127.0.0.1/'",
"lang": "Bash"
},
"awk standard deviation": {
"content": "awk '{x+=$0;y+=$0^2}END{print sqrt(y/NR-(x/NR)^2)}' filename",
"lang": "Bash"
},
"awk sum columns": {
"content": "awk '{ total += $1; count++} END {print total}' filename",
"lang": "Bash"
},
"aws ami query": {
"content": "aws ec2 describe-images --image-id ami-23456789",
"lang": "Bash"
},
"bash get script directory": {
"content": "CURRENT_DIR=\"$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd )\"",
"lang": "Bash"
},
"boto set region": {
"content": "boto3.setup_default_session(region_name='ap-southeast-2')",
"lang": "Python"
},
"convert git commit to patch": {
"content": "git format-patch -1 <sha> # This will generate a patch file\ngit apply --stat file.patch # show apply patch stats, will not change the codebase\ngit am < file.patch # Apply patch as a commit",
"lang": "Bash"
},
"convert pfx to normal ssl certificates": {
"content": "openssl pkcs12 -in domain.pfx -clcerts -nokeys -out domain.cer\nopenssl pkcs12 -in domain.pfx -nocerts -nodes -out domain.key\nopenssl pkcs12 -in domain.pfx -out domain.crt -nodes -nokeys -cacerts",
"lang": "Bash"
},
"debug SSL problem": {
"content": "openssl s_client -connect www.test.com:443 -prexit",
"lang": "Bash"
},
"decimal to hex": {
"content": "hex(dec)[2:]",
"lang": "Python"
},
"decrypt kms text": {
"content": "import base64, boto3\ndecrypt = lambda text: boto3.client('kms').decrypt(CiphertextBlob=base64.b64decode(text))\ndecrypt(text)",
"lang": "Python"
},
"dpkg show package files": {
"content": "dpkg-query -L lolcat",
"lang": "Bash"
},
"echo to stderr": {
"content": ">&2 echo \"error\"",
"lang": "Bash"
},
"extract rpm": {
"content": "rpm2cpio somefile.rpm | cpio -idmv",
"lang": "Bash"
},
"ffmpeg fix video": {
"content": "ffmpeg -err_detect ignore_err -i video.mkv -c copy video_fixed.mkv",
"lang": "Bash"
},
"ffmpeg transcode video for iPhone": {
"content": "ffmpeg -ss 1:23:45 -i somevideo.mp4 -s qvga -b:v 384k -c:v mpeg4 -r 23.976 -acodec libfaac -ac 2 -ar 44100 -an -crf 22 -deinterlace -fs 200000000 output.mp4",
"lang": "Bash"
},
"find largest files in git repo": {
"content": "git rev-list --objects --all | grep \"$(git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -10 | awk '{print$1}')\"",
"lang": "Bash"
},
"find team identifier for apps": {
"content": "codesign -dv --verbose=4 /Applications/VirtualBox.app 2>&1 | grep TeamIdentifier",
"lang": "Text only"
},
"fix email in commits": {
"content": "#!/bin/sh\n\ngit filter-branch --env-filter '\nOLD_EMAIL=\"[email protected]\"\nCORRECT_NAME=\"Kai Xia\"\nCORRECT_EMAIL=\"[email protected]\"\nif [ \"$GIT_COMMITTER_EMAIL\" = \"$OLD_EMAIL\" ]\nthen\n export GIT_COMMITTER_NAME=\"$CORRECT_NAME\"\n export GIT_COMMITTER_EMAIL=\"$CORRECT_EMAIL\"\nfi\nif [ \"$GIT_AUTHOR_EMAIL\" = \"$OLD_EMAIL\" ]\nthen\n export GIT_AUTHOR_NAME=\"$CORRECT_NAME\"\n export GIT_AUTHOR_EMAIL=\"$CORRECT_EMAIL\"\nfi\n' --tag-name-filter cat -- --branches --tags",
"lang": "Bash"
},
"get local ipaddr": {
"content": "def get_ipaddr(host=\"www.163.com\"):\n udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n try:\n udp_socket.connect((host, 9))\n ipaddress = udp_socket.getsockname()[0]\n except socket.error:\n raise\n finally:\n del udp_socket\n return ipaddress",
"lang": "Python"
},
"git add submodule": {
"content": "git submodule add ~/submd/repos/lib1.git libs/lib1",
"lang": "Bash"
},
"git diff local and server": {
"content": "git diff origin/master master",
"lang": "Bash"
},
"git remove remote branch": {
"content": "git push origin --delete <branch name>",
"lang": "Bash"
},
"git remove remote tag": {
"content": "git push --delete origin tagname",
"lang": "Bash"
},
"git setup user and email": {
"content": "git config user.email \"[email protected]\"\ngit config user.name \"Kai Xia\"",
"lang": "Bash"
},
"increase inotify watchers": {
"content": "echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p",
"lang": "Bash"
},
"linux dir in Windows": {
"content": "C:\\Users\\kentx\\AppData\\Local\\lxss\\home\\xiaket",
"lang": "Text only"
},
"list all submodules": {
"content": "git submodule foreach git pull origin master",
"lang": "Bash"
},
"load python code from file without import": {
"content": "synctaginfo = imp.new_module('synctaginfo')\nexec content in synctaginfo.__dict__\ntaginfo = synctaginfo.synctaginfo",
"lang": "Python"
},
"macos refresh disk usage": {
"content": "sudo tmutil thinLocalSnapshots / 10000000000 4",
"lang": "Bash"
},
"private network address space": {
"content": "10.0.0.0 - 10.255.255.255\n172.16.0.0 - 172.31.255.255\n192.168.0.0 - 192.168.255.255",
"lang": "Text only"
},
"python post json": {
"content": "import requests, json\nurl = 'http://127.0.0.1:27182/api/account'\nheaders = {'Content-type': 'application/json', 'Accept': 'text/plain'}\ndata = {'name': 1, 'param': 2}\nresponse = requests.post(url, data=json.dumps(data), headers=headers})",
"lang": "Python"
},
"python run overrided method from superclass": {
"content": "getattr(super(self.__class, self), sys._getframe().f_code.co_name)()",
"lang": "Python"
},
"requests disable logging": {
"content": "logging.getLogger('requests').setLevel(logging.WARNING)",
"lang": "Python"
},
"revert last git commit": {
"content": "git reset --soft HEAD~",
"lang": "Bash"
},
"rocketchat change role": {
"content": "use rocketchat\ndb.users.update({'username': 'somename'},{$set: {'roles': ['user']}})",
"lang": "JavaScript"
},
"run complex command directly through ssh using base64": {
"content": "import base64\nbase64.b64encode(\"filename=`ls /websites/webapps/somesite/logs/gc.* -1 | tail -n 1`; start=`grep -n 'Full GC' $filename | grep -v 'Ergon' |cut -d ':' -f1 | python -c 'import sys; ns= [int(n) for n in sys.stdin.read().splitlines()]; print [ns[i] for i in xrange(len(ns)-1) if ns[i] + 5 > ns[i+1]][-1]'`; end=$((start+5)); echo $filename; sed -n $start,${end}p $filename\")\nZmlsZW5hbWU9YGxzIC93ZWJzaXRlcy93ZWJhcHBzL2Nya19zdXJ2ZXlfbGl2ZS9sb2dzL2djLiogLTEgfCB0YWlsIC1uIDFgOyBzdGFydD1gZ3JlcCAtbiAnRnVsbCBHQycgJGZpbGVuYW1lIHwgZ3JlcCAtdiAnRXJnb24nIHxjdXQgLWQgJzonIC1mMSB8IHB5dGhvbiAtYyAnaW1wb3J0IHN5czsgbnM9IFtpbnQobikgZm9yIG4gaW4gc3lzLnN0ZGluLnJlYWQoKS5zcGxpdGxpbmVzKCldOyBwcmludCBbbnNbaV0gZm9yIGkgaW4geHJhbmdlKGxlbihucyktMSkgaWYgbnNbaV0gKyA1ID4gbnNbaSsxXV1bLTFdJ2A7IGVuZD0kKChzdGFydCs1KSk7IGVjaG8gJGZpbGVuYW1lOyBzZWQgLW4gJHN0YXJ0LCR7ZW5kfXAgJGZpbGVuYW1l\n\nssh someserver 'echo \"ZmlsZW5hbWU9YGxzIC93ZWJzaXRlcy93ZWJhcHBzL2Nya19zdXJ2ZXlfbGl2ZS9sb2dzL2djLiogLTEgfCB0YWlsIC1uIDFgOyBzdGFydD1gZ3JlcCAtbiAnRnVsbCBHQycgJGZpbGVuYW1lIHwgZ3JlcCAtdiAnRXJnb24nIHxjdXQgLWQgJzonIC1mMSB8IHB5dGhvbiAtYyAnaW1wb3J0IHN5czsgbnM9IFtpbnQobikgZm9yIG4gaW4gc3lzLnN0ZGluLnJlYWQoKS5zcGxpdGxpbmVzKCldOyBwcmludCBbbnNbaV0gZm9yIGkgaW4geHJhbmdlKGxlbihucyktMSkgaWYgbnNbaV0gKyA1ID4gbnNbaSsxXV1bLTFdJ2A7IGVuZD0kKChzdGFydCs1KSk7IGVjaG8gJGZpbGVuYW1lOyBzZWQgLW4gJHN0YXJ0LCR7ZW5kfXAgJGZpbGVuYW1l\" | base64 -d | bash'",
"lang": "Python"
},
"scp using tar": {
"content": "tar -C 2013 -cf - ./ | ssh 172.17.4.210 tar -C /websites/webapps/deploy/backup/mission_control_histories/2013 -xf -",
"lang": "Bash"
},
"sed delete line with pattern": {
"content": "sed '/pattern/d' filename",
"lang": "Bash"
},
"sed replace EOL": {
"content": "sed ':a;N;$!ba;s/\\n/,/g'",
"lang": "Bash"
},
"sending data to local statsd": {
"content": "echo \"deploys.test.kent:1|c\" | nc -u 127.0.0.1 8125 -w 1",
"lang": "Bash"
},
"sync a fork": {
"content": "git remote add upstream https://github.com/user/project.git\ngit fetch upstream\ngit checkout master\ngit merge upstream/master",
"lang": "Bash"
},
"sync time without ntp": {
"content": "sudo date -s \"$(curl -sD - google.com | grep '^Date:' | cut -d' ' -f3-6)Z\"",
"lang": "Bash"
},
"tar extract to folder": {
"content": "tar -xzf v0.8.0.tar.gz -C /tmp/statsd",
"lang": "Bash"
},
"tcpdump sniff syslog traffic": {
"content": "tcpdump -Xni lo port 1514",
"lang": "Text only"
},
"tell innodb and myisam": {
"content": "SHOW TABLE STATUS WHERE Name = 'tablename';",
"lang": "SQL"
},
"unzip archive with non-ascii charset": {
"content": "unar -f -e gb18030 *.zip",
"lang": "Bash"
},
"upgrade all pip packages": {
"content": "python -c 'import pip,subprocess; [subprocess.call(\"pip install -U \" + d.project_name, shell=True) for d in pip.get_installed_distributions()]'",
"lang": "Python"
},
"user dynamodb as lock": {
"content": "aws dynamodb put-item --table-name MusicCollection --item '{\"Artist\": {\"S\": \"Obscure Indie Band\"}}' --condition-expression \"attribute_not_exists(Artist)\"",
"lang": "Bash"
},
"validate json file": {
"content": "cat lisen.json | python -c \"import json, sys; print json.loads(sys.stdin.read())\"",
"lang": "Bash"
}
}