Skip to content

Instantly share code, notes, and snippets.

View dsaw's full-sized avatar

देवेश (devesh) dsaw

View GitHub Profile
@dsaw
dsaw / bits-stdc++.h
Created July 23, 2023 10:06 — forked from Einstrasse/bits-stdc++.h
bits/stdc++.h header file
// C++ includes used for precompiling -*- C++ -*-
// Copyright (C) 2003-2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
@dsaw
dsaw / latency.txt
Created February 6, 2022 14:29 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@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:

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 / 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
@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 / 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 / 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 / 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 / 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):
'''