-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheatsheet
More file actions
645 lines (490 loc) · 20.7 KB
/
cheatsheet
File metadata and controls
645 lines (490 loc) · 20.7 KB
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
=== G I T ===
.) merge specific files from another branch
git checkout --patch source_branch file_to_merge
.) merge squash commits
git merge --squash branch_name
.) merge ignore white space
git merge -Xignore-space-change branch_name
.) create branch (and switch to it at the same time)
git switch -c iss53
git checkout -b iss53
.) delete branch
git push -d origin <branch_name> # delete remote branch
git branch -d <branch_name> # delete local branch
.) prune branches (deleting references to non-existing remote branches)
git remote prune origin
- where origin comes from ...
$ git remote -v
$ origin https://gitserver.com/user/repository.git (fetch)
.) rename branch
git branch -m new_branch # Rename branch locally (if in the branch to be renamed)
git push -d origin old_branch # delete remote branch
.) tag (http://git-scm.com/book/en/v2/Git-Basics-Tagging)
git tag -a <tag_name> <commit_sha> -m 'message'
git tag -a v0.1.2 -m 'tag v0.1.2'
git push origin v0.1.2
git checkout tags/v0.1.2
git checkout master
git show v0.1.2 # show tag data
git tag -n | sort -V # show tag message (for annotated tags)
# List Git tags with creation date and tag message (if annotated)
git for-each-ref --sort=creatordate --format='%(creatordate:short) %(refname:short): %(contents)' refs/tags
git ls-remote --tags --ref origin # show tag git sha
.) delete tag
git tag -d v3.6.2
git push -d origin v3.6.2
.) Show history for a specific line
git log -L 42,42:src/app.py # show history for line 42 only
git log -L :function_name:src/app.py # Show history for a function name instead of line numbers ...
.) rename tag
git tag new_tag old_tag
git push --tags
git tag -d old_tag
git push origin --delete old_tag
.) show all commits on all branches that aren't pushed yet
git log --branches --not --remotes
git log --branches --not --remotes --simplify-by-decoration --decorate --oneline
# to push changes from all branches
git push --all
.) checkout by date
git checkout `git rev-list -n 1 --first-parent --before="2020-07-27 13:37" master`
.) clone tag v3.6
git clone --branch v3.6 https://github.com/tecris/docker.git
.) show last commit
git show
.) log
git log --pretty=format:"%h %an %s"
git cherry -v master # show only logs from branch
git log --name-status # full path names and status of changed files
git log --name-only # full path names of changed files
git log --stat # abbreviated pathnames and a diffstat of changed files
git log --oneline # show one line only
.) compare changes for a file between revisions:
git diff revision_1 revision_2 -- File_name
.) kind of info
git remote show origin
git remote -v
.) revert uncommitted changes
.) revert single file
git checkout -- filename
.) revert all files
git reset --hard
.) revert git submodules
git submodule update --init
.) revert the reverted merge (https://www.drupaldump.com/gitlab-revert-reverted-merge)
git pull master
git checkout -b new_branch
git revert -m 1 37dsd67a48
.) remove last commit
.) remove a commit done locally
git reset --soft HEAD^
.) remove a commit already pushed
git revert <commit-hash>
.) revert
git revert commit_ref_sha
git revert HEAD # revert last commit
.) revert local commits
.) moves the current branch backward by two commits and keep work done
git reset --soft HEAD~2
.) moves the current branch backward by two commits and deletes work done
git reset --head HEAD~2
.) remove all files added since last commit
git clean -fd
.) numeric versioning
.) git rev-list HEAD --count
-) http://programmers.stackexchange.com/questions/141973/how-do-you-achieve-a-numeric-versioning-scheme-with-git
Use tags to mark commits with version numbers:
.) git tag -a v2.5 -m 'Version 2.5'
Push tags upstream—this is not done by default:
.) git push --tags
Then use the describe command:
.) git describe --tags --long
This gives you a string of the format:
.) v2.5-0-deadbeef
.) v2.5 - last tag
.) 0 - number of commits since last tag
.) deadbeef - SHA of HEAD
.) stash
git stash list
git stash push -m 'ZTG-7064, 1st commit' # stash changes
git stash push -u -m 'ZTG-7064, 1st commit' # untracked files stashed as well
git stash apply --index 0 # apply but do not remove the state from the stash list
git stash drop stash@{0} # Remove, single, stash entry
git stash show [-p]
git stash show -p stash@{0} > stash.diff
git apply stash.diff
git diff stash@{0}
git diff stash@{0} stash@{1}
.) editor
.) git config --global core.editor "vim"
.) Github - Bitbucket mirroring
.) deanclatworthy.com/2013/01/how-to-avoid-relying-on-github-mirror-your-repository
.) Get github repos:
.) $ curl --silent https://api.github.com/users/tecris/repos |grep '\"git_url\"' | awk -F': "' '{print $2}' | sed -e 's/",//g'
=== MONOREPO ===
https://github.com/babel/babel/blob/master/doc/design/monorepo.md
=== K U B E C T L ===
$ kubectl api-resources
$ kubectl -n fluxcd get secret
$ kubectl -n fluxcd delete secret fluxcd-git-deploy
$ kubectl -n rango create secret generic regcred --from-literal=username='django' --from-literal=password='!admin*f9%6#76' --dry-run=client -o yaml | kubectl apply -f -
$ kubectl -n fluxcd create secret generic fluxcd-git-deploy --from-file=identity=./id_rsa_bitbucket --dry-run=client -o yaml | kubectl apply -f -
$ kubectl -n rango create secret generic postgrez --from-literal=password='!admin*f9%6#76'
$ kubectl -n rango get secret postgrez --output="jsonpath={.data.password}" | base64 -d
$ kubectl -n rango get secret ingress-tls-cert -o json
$ kubectl -n rango get secret ingress-tls-cert --output="jsonpath={.data.tls\.crt}" | base64 -d # alpine
$ kubectl -n rango get secret ingress-tls-cert --output="jsonpath={.data.tls\.crt}" | base64 --decode # ubuntu
$ kubectl -n rango get po --field-selector=status.phase=Running
$ kubectl -n rango get po --field-selector=status.phase=Running -o name -l app=test-service | xargs kubectl -n rango describe
$ kubectl -n rango rollout restart deployment test-service
=== H E L M ===
$ helm -n rango get values --revision=13 test-service
$ helm -n rango get values --revision=24 test-service -o json |jq [.resources]
$ helm -n rango history test-service
$ helm -n rango list
$ helm -n rango status test-service
=== jq ===
$ az vm list | jq -r ".[] | select(.name == \"some_name\") | .id"
$ az vm list | jq -r ".[] | {name,id} | select(.name == \"some_name\") | .id"
# if above returns multiple entries(same value) and we need just one
$ az vm list | jq -r "[.[] | {name,id} | select(.name == \"some_name\")][0] | .id"
$ az vm list | jq -r ".[].name | select(startswith(\"who_am_i\"))"
$ az vm list | jq -r ".tags.id"
$ az vm list | jq -r ".tags | sort[] | select(startswith(\"tag_to_search\"))"
$ az vm list | jq ".values[] | select(.display_name == \"rango here\") | {account_id}"
=== M A V E N ===
.) Versions plugin. (mojohaus.org/versions-maven-plugin)
..) mvn versions:display-dependency-updates # display dependencies with newer versions available.
..) mvn versions:use-latest-versions # replaces any version with the latest version.
..) mvn versions:update-properties # sets properties to the latest versions of specific artifacts.
..) mvn versions:display-plugin-updates # displays all plugins that have newer versions available.
.) https://www.artifact-listener.org # email notifications when newer artifacts versions are available on Maven Central
.) Dependency plugin (maven.apache.org/plugins/maven-dependency-plugin)
..) mvn dependency:tree
..) mvn dependency:tree -Dincludes=org.springframework.kafka:spring-kafka
..) mvn dependency:analyze -DignoreNonCompile=true
.) Tidy Maven Plugin.(mojohaus.org/tidy-maven-plugin)
..) mvn tidy:pom # sort the sections of a pom.xml into the canonical order.
.) mojohaus.org/exec-maven-plugin
..) mvn exec:java -Dexec.mainClass=org.test.Main
.) archetype (maven-repository.com/archetypes)
mvn archetype:generate -Dfilter=serenity
mvn archetype:generate \
-DgroupId=org.demo.app \
-DartifactId=quickstart \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DinteractiveMode=false
mvn archetype:generate \
-DgroupId=org.demo.app \
-DartifactId=wildfly-html5 \
-DarchetypeGroupId=org.wildfly.archetype \
-DarchetypeArtifactId=wildfly-html5-mobile-archetype \
-DarchetypeVersion=8.2.0.Final \
-DinteractiveMode=false
.) help for a plugin
mvn help:describe -DgroupId=org.flywaydb -DartifactId=flyway-maven-plugin -Dversion=3.2.1 -Dfull=true
.) other
mvn site:site
mvn assembly:assembly
mvn install -DskipTests
mvn -Dwtpversion=2.0 eclipse:eclipse
mvn eclipse:eclipse
mvn eclipse:clean eclipse:eclipse -DdownloadSources=true
mvn eclipse:clean
mvn --dryRun release:prepare
mvn release:clean
mvn release:prepare
.) show project version
$ mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec
=== F O R G E ===
forge -e "run forge_script.fsh"
http://forge.jboss.org/document/hands-on-lab
=== G I T H U B ===
https://github.com/search?q=stars:%3E1&s=stars&type=Repositories // show repos with most stars
=== public ip address ===
.) https://api.ipify.org/
=== L I N U X ===
.) xargs basics -> https://shapeshed.com/unix-xargs/
.) password
$ head -c32 /dev/urandom | base64
.) SSH port forwarding
$ ssh -L 8888:localhost:8888 HOSTNAME
and then open http://localhost:8888
.) grep
.) OR Using \|
.) grep 'pattern1\|pattern2' filename
.) NOT using grep -v
.) grep -v 'pattern1' filename
.) reduce pdf file size
.) ps2pdf -dPDFSETTINGS=/ebook input.pdf output.pdf
.) merge pdf files
.) gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf a.pdf b.pdf
.) search and replace
$ sed -i -e 's/string1/string2/g'
.) Nice sed tutorial https://gist.github.com/un33k/1162378
.) # substitute "foo" with "bar" EXCEPT for lines which contain "baz"
$ sed '/baz/!s/foo/bar/g'
.) recursive search and replace
$ grep -rl matchstring somedir/ | xargs sed -i 's/string1/string2/g'
.) delete recursive svn folder
#!/bin/sh
echo "recursively removing .svn folders from"
pwd
rm -rf `find . -type d -name .svn`
.) search for a file with find
$ find -iname \*lerts-properties-service.xml
$ find -iname \*lerts\*
.) script to rename a directory
#! /bin/bash
# replace directory 'com' with 'org'
# Search and rename directories.
for filename in `find . -type d -name com` #Traverse all files in directory.
do
fname=$filename # Yes, this filename needs work.
n=`echo $fname | sed -e "s/com/org/g"` # Substitute
mv "$fname" "$n" # Do the actual renaming.
done
.) Find and trace process
$ ps auxww | grep java
$ $ strace -p <pid>
.) List The Open Ports And The Process That Owns Them
$ sudo lsof -i
..) id using port 8080 (tcp)
$ sudo lsof -i TCP:8080
$ sudo netstat -lptu
.) SSH hardening
-) https://www.ibm.com/developerworks/aix/library/au-sshlocks
.) Script to check if port open
-------------------------------------------------
#/bin/bash
SERVER=127.0.0.1 PORT=5000
if (: < /dev/tcp/$SERVER/$PORT) 2>/dev/null
then
echo "Port $PORT is already used"
else
echo "Port $PORT not used"
fi
-------------------------------------------------
.) one liner check port open
$ nc -zvw 1 linuxfoundation.org 80
.) tail -f server/default/log/server.log | awk '{print $2"\t"$4}'
.) format json
$ cat mjson.tool | jq
$ python -mjson.tool j.txt
.) xml formating
$ xmllint --format pom.xml > a.xml
# by default xmllint uses 2 spaces for indentation, to specify a different level set XMLLINT_INDENT variable. For exmaple for 4 spaces use
$ export XMLLINT_INDENT=' ';xmllint --format pom.xml > a.xml
$ xmllint utility comes with libxml2-utils
.) curl (http://blogs.plexibus.com/2009/01/15/rest-esting-with-curl)
-) POST
$ curl -i -H "accept: application/json" -X POST -d "firstName=james" http://192.168.0.165/persons/person
where,
i - show response headers
H - pass request headers to the resource
X - pass a HTTP method name
d - pass in parameters enclosed in quotes; multiple parameters are separated by '&'
The above command posts the first name "james" to the persons resource. Assuming the server creates a new person resource with first name of James, I also
tell the server to return a json representation of the newly created resource.
.) Send file
$ curl -i -H "content-type: text/xml" -d @request.xml http://localhost:8080/ws # send file
.) Send json, expect json
$ curl -i -H "content-type: application/json" -H "accept: application/json" -X POST -d '{"name":"Salvador","iso":"SLV"}' http://localhost:8080/rest/country
-) GET
$ curl -i -H "accept: application/json" http://192.168.0.165/persons/person/1
-) PUT
$ curl -i -H "accept: application/json" -X PUT -d "phone=1-800-999-9999" http://192.168.0.165/persons/person/1
-) DELETE
$ curl -i -H "accept: application/json" -X DELETE http://192.168.0.165/persons/person/1
.) Random shuffle a file
$ shuf < inputfile > outputfile
$ sort -R > randomsortedfile
.) Check available versions for a package
$ sudo apt-cache policy ansible # check available versions for ansible
.) show process and wrap lines
$ ps aux | less -S # use arrow keys, or Esc-( and Esc-), or Alt-( and Alt-)
$ ps aux | most # use arrow keys, or < and > (Tab can also be used to scroll right)
.) disk space
$ du -sh ./* | sort -h
$ df -h
$ lsblk
$ ncdu
=== W E B D A V ===
cadaver https://demo.org/repository/experimental/org/demo/tns
konqueror webdavs://demo.org/repository/experimental/org/demo/tns/
=== L O G 4 J ===
www.javaworld.com/jw-11-2000/jw-1122-log4j.html
The root category defaults to DEBUG, and following config are equivalent:
<root>
<appender-ref ref="FILE"/>
</root>
and
<root>
<priority value="DEBUG" />
<appender-ref ref="FILE"/>
</root>
If no category specified for a package/class it will inherit root category.
For example, messages with priority DEBUG or higher will be sent ot the
FILE appender.(The FILE appender will discard messages with priority lower
than ERROR)
...
<appender name="FILE" ...
...
<param name="Threshold" value="ERROR"/>
...
</appender>
<root>
<priority value="DEBUG" />
<appender-ref ref="FILE"/>
</root>
...
Package org.apache category set to(restricted to) INFO, all other categories are
inheriting the root category (WARN).
FILE appender discards messages with priority LOWER than ERROR.
...
<appender name="FILE" ...
...
<param name="Threshold" value="ERROR"/>
...
</appender>
<category name="org.apache">
<priority value="INFO"/>
</category>
<root>
<priority value="WARN" />
<appender-ref ref="FILE"/>
</root>
...
=== S O L A R I S ===
http://www.unixguide.net/sun/sunoneliners.shtml
Grep
/usr/local/bin/grep
or
/usr/sfw/bin/ggrep
- recursive grep
find . | xargs grep 'Your Grep Value'
- find file
find /opt/tibco/ -name "*tibe*"
Tar
tar cvf - /home/ebs | gzip - > ebs.tar.gz
gtar xzvf somefile.tar.gz
Resource statistics for each thread of a server application.
prstat -L -p 3295
=== N O D E . J S ===
https://github.com/angular-fullstack/generator-angular-fullstack
https://github.com/DaftMonk/fullstack-demo
https://www.npmjs.com/about
.) Chat
https://github.com/sdelements/lets-chat
=== O T H E R ===
.) https://ozh.github.io/ascii-tables/ -> ASCII (separated)
=== D O C K E R ===
DNS
https://github.com/tianon/rawdns
DNS with Docker (nice) ---
http://www.damagehead.com/blog/2015/04/28/deploying-a-dns-server-using-docker/
Docker – a DNS server container ---
http://www.monblocnotes.com/node/2074
How ubuntu:14.04.1 image is built ---
http://www.monblocnotes.com/node/2072
Docker containers on desktop ---
https://blog.jessfraz.com/post/docker-containers-on-the-desktop/
https://github.com/jfrazelle/dockerfiles
Email
http://www.centurylinklabs.com/tutorials/killing-your-outlook-with-docker-and-davmail
=== T E C H N O ===
JEE
http://blog.eisele.net/2015/12/a-refresher-top-10-java-ee-7-backend.html
Build number
http://www.jayway.com/2012/04/07/continuous-deployment-versioning-and-git
Java properties
http://owner.aeonbits.org/docs/reload/
JPA - sequence generator
http://www.javabeat.net/jpa-annotations-generatedvalue-sequencegenerator-tablegenerator
http://gafter.blogspot.com/2008/01/is-java-dying.html
Reflecting generics
http://www.artima.com/weblogs/viewpost.jsp?thread=208860
Generics erasure
http://gafter.blogspot.com/2004/09/puzzling-through-erasure-answer.html
Super Type Tokens
http://www.artima.com/weblogs/viewpost.jsp?thread=206350
http://gafter.blogspot.com/2006/12/super-type-tokens.html
Factories with Generics
www.developerdotstar.com/mag/articles/troche_factorychain.html
Guidelines for using volatile variables
www.ibm.com/developerworks/java/library/j-jtp06197.html
Threads
www.briangoetz.com/pubs.html
www.baptiste-wicht.com/2010/08/java-concurrency-part-4-semaphores
tutorials.jenkov.com/java-concurrency/index.html
www.artima.com/insidejvm/ed2/jvm2.html
Stack and heap
http://www.javatutorialhub.com/java-stack-heap.html
ThreadLocal
www.ibm.com/developerworks/java/library/j-threads3.html
Understanding Java Multithreading and Read-Write Locks
www.developer.com/java/article.php/951051
@XmlRootElement
weblogs.java.net/blog/kohsuke/archive/2006/03/why_does_jaxb_p.html
jsexton0.blogspot.com/2009/02/marshalling-and-unmarshalling-without.html
http://jaxb.java.net/guide/Customizing_Java_packages.html
Generate an XML Document from an Object Model with JAXB 2
www.devx.com/Java/Article/34069/1763/page/3
Fork and Join, Parallel Programming
http://www.oracle.com/technetwork/articles/java/fork-join-422606.html
OpenMQ
http://mq.java.net
Apache Qpid (Advanced Message Queueing Protocol)
http://qpid.apache.org
12Factor
http://12factor.net
Alternative java web frameworks
sparkjava.com
ratpack.io
BULK
https://blog.codecentric.de/en/2011/03/automated-acceptance-testing-using-jbehave
https://blog.codecentric.de/en/2012/06/jbehave-configuration-tutorial
http://www.thucydides.info/docs/serenity
http://en.wikipedia.org/wiki/Specification_by_example
=== S V N ===
.) tag
svn copy http://subversion/project/trunk \
http://subversion/project/tags/project-0.0.2 \
-m "Tagging the -r xx version as the X.X.X release"
.) Roll back to version 15898
svn merge -r HEAD:15898 http://subversion/svn/project/trunk .
.) Roll back to a version
svn merge -rXX:YY (YY is the number of the revision you want to revert to)
.) Merge from trunk into
Merge in the current directory changes that occurred in the trunk from
revision 15933 to 16026
svn merge http://subversion/svn/project/trunk -r15933:16026 .
.) Ignore
on 'svn status' ignore these files
..) Create file ("a_file") with file patterns svn to ignore.
..) Then run the command,
svn propset svn:ignore . -F file_name
...) recursive
svn -R propset svn:ignore . -F file_name
..) Edit.
svn propedit svn:ignore .
.) Diff
'svn diff --diff-cmd diff -x -uw /path/to/file'
.) Set svn editor
export SVN_EDITOR=vi
.) Create svn project
mkdir -p test/my_project
cd test/my_project
mkdir -p trunk/my_module tags branches
cd ../..
svn import my_project http://subversion/my_project -m "First Import"
.) svn copy http://subversion/svn/some_location http://subversion/svn/other_location -m 'a comment'
.) svn move http://subversion/svn/some_location http://subversion/svn/other_location -m 'a comment'
.) non recursive checkout
svn checkout --non-recursive http://svnserver/trunk/ proj
.) Check modifications on server
svn st -u
.) Show annotations (aka blame)
svn blame file_name
.) Setting svn mime type to text
svn propset svn:mime-type text/plain pom.xml