Skip to content

Instantly share code, notes, and snippets.

View dsaw's full-sized avatar

देवेश (devesh) dsaw

View GitHub Profile
@dsaw
dsaw / c++Template.cpp
Created December 3, 2017 06:29 — forked from kodekracker/c++Template.cpp
Basic C++ Template for Competitive Programming
/*
* Note: This template uses some c++11 functions , so you have to compile it with c++11 flag.
* Example:- $ g++ -std=c++11 c++Template.cpp
*
* Author : Akshay Pratap Singh
* Handle: code_crack_01
*
*/
/******** All Required Header Files ********/
@dsaw
dsaw / vimdiff.md
Last active May 3, 2018 16:52 — forked from mattratleph/vimdiff.md
vimdiff cheat sheet

vimdiff cheat sheet

git mergetool

In the middle file (future merged file), you can navigate between conflicts with ]c and [c.

Choose which version you want to keep with :diffget LO or :diffget RE (the LO and RE are unique identifiers for the target/master copy and the merge/branch copy file names).

:diffupdate (to remove leftover spacing issues)

:only (once you’re done reviewing all conflicts, this shows only the middle/merged file)

@dsaw
dsaw / kdtree.py
Last active May 18, 2018 20:26
Straightforward implementation of 2-d tree in Python.
import unittest
## Kd-tree implementation
## 2d tree
## search, insert
class Node:
def __init__(self,x,y,cmp_x):
'''
@dsaw
dsaw / factorial.py
Created August 20, 2018 16:49 — forked from ChrisPenner/factorial.py
Tail Recursion in Python without Introspection
from tail_recursion import tail_recursive, recurse
# Normal recursion depth maxes out at 980, this one works indefinitely
@tail_recursive
def factorial(n, accumulator=1):
if n == 0:
return accumulator
recurse(n-1, accumulator=accumulator*n)
@dsaw
dsaw / memoized.py
Created August 20, 2018 17:11
Memoized fibonacci in Python
# https://dbader.org/blog/python-memoization
# Example learned from there
def memoize(func):
cache = dict()
def memoized_func(*args):
if args in cache:
@dsaw
dsaw / js_binding_rules.js
Created October 24, 2018 05:21
Little script to recap on this binding rules.
function displaySome(blah)
{
console.log(this.blah);
console.log(this);
}
var blah = "suit yourself!";
@dsaw
dsaw / max_heap.py
Created April 12, 2020 11:30 — forked from pavlin-policar/max_heap.py
Python implementation of max heap/priority queue
class MaxHeap:
def __init__(self, collection=None):
self._heap = []
if collection is not None:
for el in collection:
self.push(el)
def push(self, value):
self._heap.append(value)
@dsaw
dsaw / gist:08a04cb75a0d2b84dbc516609a356335
Last active August 8, 2020 09:03 — forked from jacksonfdam/gist:3000275
Regular Expressions List
//Regular Expressions List
//Short Tutorial
\ // the escape character - used to find an instance of a metacharacter like a period, brackets, etc.
. // match any character except newline
x // match any instance of x
^x // match any character except x
[x] // match any instance of x in the bracketed range - [abxyz] will match any instance of a, b, x, y, or z
| // an OR operator - [x|y] will match an instance of x or y

Contributing

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

Pull Request Process

  1. Ensure any install or build dependencies are removed before the end of the layer when doing a
@dsaw
dsaw / prime_testing.py
Created December 25, 2020 12:06
elementary primality testing algos
from random import randint
import logging
from codetiming import Timer
logging.basicConfig(level=logging.DEBUG)
# Primality testing script for miller rabin & fermat tests
# https://crypto.stanford.edu/pbc/notes/numbertheory/millerrabin.html
# https://cp-algorithms.com/algebra/primality_tests.html
def probablyPrimeFermat(N, tries=5):
if N < 4: