Skip to content

Instantly share code, notes, and snippets.

@danyaljj
danyaljj / vim.txt
Created June 26, 2015 00:31
vim gist
=== VIM notes
save: :w
save and exit: :x
Search forward: /pattern
Search backward ?pattern
Continue forward search n
Continue backward search N
@danyaljj
danyaljj / terminal.sh
Last active May 12, 2017 17:12
terminal gist
Bash / Terminal / Shell notes
================================
* Script header
#!/bin/bash
* Decompression:
$ tar -zxvf filename.tgz
$ tar -zxvf filename.tar.gz
@danyaljj
danyaljj / countS3md.md
Created June 26, 2015 00:33
Count the number of the files in your bucket

Count the number of the files in your bucket s3cmd ls -r s3://logs.mybucket/subfolder/ | wc -l

@danyaljj
danyaljj / python.txt
Created June 26, 2015 00:34
python gist
# PythonNotes
## Started Jan, 2015
== String
s="hello world"
s.replace("hello", "pillo")
s.upper()
b = s.split()
space=" "
space.joib(b) # combines list of strings with spaces in between
@danyaljj
danyaljj / mc.txt
Created June 26, 2015 00:34
midnight commander gist
== Midnight Commander
==== Esc
Quick change directory: Esc + c
Quick change directory history: Esc + c and then Esc + h
Quick change directory previous entry: Esc + c and then Esc + p
Command line history: Esc + h
Command line previous command: Esc + p
View change: Esc + t (each time you do this shortcut a new directory view will appear)
Print current working directory in command line: Esc + a
@danyaljj
danyaljj / readHeadAndTail.sh
Created June 26, 2015 02:10
read head and tail of files
# Read the last 10k lines, then read the 1st 5k lines from that.
cat myfile | tail -10000 | head -5000 > newfile
@danyaljj
danyaljj / mongo_shell
Created June 28, 2015 01:36
Remembering MongoDB shell commands
show dbs // show all the existing dbs on the server.
use db_name // use the db with name 'db_name'
db // name of the db currently being used
show collections // show information in the db
db.collection_name.insert({title: 'Hey MongoDB'}) // Creating the collection 'collection_name' and adding an entry to it
db.collection_name.count() // give the count of entries in the collection
for(var i=0; i < 10; i++) db.collection_name.insert({ number: i }) // loops work in the mongoDB shell! :)
db.collection_name.find().pretty() // print everything in pretty format inside the 'collection_name'.
db.collection_name.find({ number: 2 }) // finds the collection with specific definition
db.collection_name.find().sort({number: 1}) // sorts based on the numbers increasing (in alphabetic order). To ger the reverse we can use {number: -1}
@danyaljj
danyaljj / pick_unpickle.scala
Created July 8, 2015 08:23
Pickle/Unpickle with files (Scala)
// more here: https://github.com/scala/pickling
// note that for each element of the class, there needs to be an implicit function defning pickle/unpickle procedure.
def pickleCacheToFile(): Unit = {
println("saving to file ... ")
val cacheByteArray = objectVar.pickle.value
val fos = new FileOutputStream(objectVar)
fos.write(cacheByteArray)
fos.close()
}
@danyaljj
danyaljj / sort_map_js
Created July 16, 2015 23:03
Sort map by its keys and return another map in Javascript
sortMapByValue(map) {
var tupleArray = [];
for (var key in map) tupleArray.push([key, map[key]]);
tupleArray.sort(function (a, b) {
return b[1] - a[1]
});
var sortedMap = {};
tupleArray.forEach(function (el) {
sortedMap[el[0]] = el[1]
});
@danyaljj
danyaljj / mapToArrayAndTheOtherWay
Created July 16, 2015 23:13
Convert Map to Array of 2-Arrays and vice versa
// to Map
var tupleArray = [[1,2], [3,4]];
var outputMap = {};
tupleArray.forEach(function (el) {
outputMap[el[0]] = el[1]
});
// from Map
var inputMap = {1: 2, 3: 4}
var tupleArrayOut = Object.keys(inputMap).map(function(e, i){