Skip to content

Instantly share code, notes, and snippets.

View worldofprasanna's full-sized avatar
🔥
Game is on

Prasanna worldofprasanna

🔥
Game is on
View GitHub Profile
@worldofprasanna
worldofprasanna / array_to_hash.rb
Created November 7, 2015 16:30
Snippet to convert Array to Hash with duplicate elements combined together
def array_to_hash(arr)
hash_val = Hash.new
arr.uniq.each {|n| hash_val[n] = arr.grep(n)}
hash_val
end
# array_to_hash([1,2,3,2,1]) => {1=>[1, 1], 2=>[2, 2], 3=>[3]}
@worldofprasanna
worldofprasanna / hoisting.js
Last active March 13, 2016 05:40
Hoisting Issue
function printName(isFirstName){
console.log(firstName); // Variables hoisted to the top
console.log(lastName);
if (isFirstName){
var firstName = 'Prasanna';
}else {
var lastName = 'V'
}
}
@worldofprasanna
worldofprasanna / employee.js
Last active March 13, 2016 06:09
Class in ES6
class Person {
constructor(name){
this.name = name;
}
}
class Employee extends Person {
constructor(id, name){
super(name);
this.id = id;
@worldofprasanna
worldofprasanna / with-statement.py
Last active August 15, 2016 20:22
With statements in Python
# Java style of file handling
# Good example of sandwich code
filename='test.txt'
try:
file = open(filename)
print(file.readlines())
except Exception as e:
print(e.args[0])
finally:
@worldofprasanna
worldofprasanna / proxy-pattern.py
Last active August 28, 2016 14:38
Proxy pattern implemented in python-koans
class Proxy:
def __init__(self, target_object):
object.__setattr__(self, 'msg', OrderedDict())
object.__setattr__(self, '_obj', target_object)
def __getattr__(self, name):
if name in self.msg:
self.msg[name] += 1
else:
self.msg[name] = 1
@worldofprasanna
worldofprasanna / docker-handy-ref.sh
Last active March 6, 2017 23:46
Docker basic commands for reference
# pull & start the container
docker run busybox
# list all the images
docker images
# to remove all the images
docker rmi $(docker images -q)
# to remove the exited containers
@worldofprasanna
worldofprasanna / useful-debugging-commands.sh
Created September 11, 2016 06:41
Network and OS commands
# to find a pid by port
lsof -n -i:$PORT | grep LISTEN
@worldofprasanna
worldofprasanna / vim-plugings-ref.md
Last active November 3, 2016 16:50
Quick Ref for vim plugins used

Nerd Tree

  • To show hidden files - I
  • To toggle NerdTree - Ctrl + n

Vim Surround

  • To surround a word with " - ysiw" (instead of iw - other text objects can be used like ip, iW )
  • To change " to ' - cs"'

Zoom Vim

To toggle zoom in a pane - Ctrl + w, o

@worldofprasanna
worldofprasanna / vim-org-mode-gotchas.md
Last active November 3, 2016 16:53
Quick Ref for Vim org mode

Useful commands in vim-orgmode

Headers

      1. *, **, etc for creating headings, sub headings
      2. To continue headers, press <enter> in normal mode
      3. >>, << to convert sub headers to headers or vice versa
      4. <Tab> and <S-Tab> to fold headers
      5. zm, zr to close the whole list
@worldofprasanna
worldofprasanna / docker-handy-ref-2.sh
Last active March 7, 2017 01:18
Docker useful commands
Reference: https://prakhar.me/docker-curriculum/#busybox
# Run a static website in background. d - detach mode, P - expose all ports, --name give name to the running container
docker run -d -P --name static-site prakhar1989/static-site
# To see the ports used
docker port static-site
# Docker networks