Skip to content

Instantly share code, notes, and snippets.

View ishankhare07's full-sized avatar
👨‍💻

Ishan Khare ishankhare07

👨‍💻
View GitHub Profile
@ishankhare07
ishankhare07 / address_spaces.c
Last active April 1, 2018 08:50
A C program showing the structure of address spaces
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("location of Code: %p\n", (void *) main);
printf("location of Heap: %p\n", malloc(1));
int x = 10;
printf("location of Stack: %p\n", &x);
return 0;
}
@ishankhare07
ishankhare07 / qsort.erl
Created November 28, 2017 19:28
famous quicksort in erlang
-module(qsort).
-export([qsort/1]).
qsort([]) -> [];
qsort([H|T]) ->
qsort([X || X <- T, X < H]) ++ [H] ++ qsort([X || X <- T, X > H]).
@ishankhare07
ishankhare07 / timer.erl
Created November 28, 2017 16:41
a timer in erlang
-module(timer).
-export([start/2, cancle/1]).
start(Time, Fun) ->
spawn(fun() -> timer(Time, Fun) end)).
cancle(Pid) -> Pid ! cancle.
timer(Time, Fun) ->
receive
@ishankhare07
ishankhare07 / func_qsort.py
Created November 24, 2017 09:37
erlang style functional quick sort
def qsort(l):
if not l:
return []
else:
pivot, tail = l[0], l[1:]
return qsort([x for x in tail if x < pivot]) + [pivot] + qsort([x for x in tail if x >= pivot])
a = {}
a['name'] = 'ishan'
console.log(a)
// { name: 'ishan' }
// or the other way
a.age = 24
console.log(a)
// { name: 'ishan', age: 24 }
a = {}
# add a key-value pair
a['name'] = 'ishan'
# lets see whats in there
print(a)
# {'name': 'ishan'}
# add more key-value pairs
@ishankhare07
ishankhare07 / hide.js
Last active August 14, 2017 05:04
hide annoying sarahah posts from fb news feed
document.querySelectorAll('._5pcr.fbUserPost')
.forEach((element) => {
if(element.innerHTML.match(/sarahah/)) {
element.style.visibility = 'hidden';
}
})
-module(star_pattern).
-export([print/2]).
for(N, N, Symbol) -> io:format("~s", [Symbol]);
for(X, N, Symbol) ->
io:format("~s",[Symbol]),
for(X, N-1, Symbol).
print(Symbol, Times) ->
@ishankhare07
ishankhare07 / complex.py
Last active August 22, 2016 21:41
Anatomy of python classes | run this code here -> https://repl.it/CqLt/3
def add(self, other): # overloading + operator
return self.__class__(self.a + other.a, self.b + other.b)
def sub(self, other): # overloading - operator
return self.__class__(self.a - other.a, self.b - other.b)
def constructor(self, a = 0, b = 0): # to be constructor
self.a = a
self.b = b
# Sample minimal config file. Copy this to ~/.offlineimaprc and edit to
# get started fast.
[general]
accounts = Gmail
[Account Gmail]
localrepository = Gmail-Local
remoterepository = Gmail-Remote