Skip to content

Instantly share code, notes, and snippets.

import sys, marshal, functools, subprocess
child_script = """
import marshal, sys, types;
fn, args, kwargs = marshal.load(sys.stdin)
marshal.dump(
types.FunctionType(fn, globals())(*args, **kwargs),
sys.stdout)
"""
@vasanthk
vasanthk / System Design.md
Last active April 18, 2024 13:23
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@scturtle
scturtle / test.bf
Created April 30, 2014 07:28
print 0 to 99 in brainfuck
ref: http://www'iwriteiam'nl/Ha_bf_intro'html
>++++++++++[<++++++++++>-] (#0=100)
>+++++++[<+++++++>-]+++++++++++<--< (#1=47 #2=11)
[ (loop #0)
>+ (inc #1)
>- (dec #2)
(test if #2 is 0 using #3 #4)
[>+>+<<-] >[<+>-] (move #2 to #3 #4; move #3 to #2)
@scturtle
scturtle / bf.hs
Created April 28, 2014 02:57
Brainfuck Intepreter
{-# OPTIONS_GHC -O2 -optc-O2 #-}
import Control.Monad
import Text.ParserCombinators.Parsec
import Control.Monad.State
import Data.Array.IO
import Data.Char
import Debug.Trace
data Stmt = INCPNT | DECPNT | INC | DEC | OUTPUT | READ
| Loop [Stmt]
import cv2
import numpy as np
canny = rho = threshold = minLen = maxGap = None
def draw():
lines = cv2.HoughLinesP(canny, rho, np.pi / 180,
threshold, None, minLen, maxGap)
dst = cv2.cvtColor(canny, cv2.COLOR_GRAY2BGR)
@scturtle
scturtle / rg.py
Last active May 2, 2020 04:33
Answer to regex golf http://regex.alf.nu/
plain = r'foo'
anchor = r'k$'
ranges = r'^[a-f]*$'
backrefs = r'(...).*\1'
abba = (r'^(?!' # don't (
r'.*(.)(.)\2\1.*' # parttern like abba
r'$)') # ) select
plan = r'^(.)(.).*\2\1$'
@scturtle
scturtle / addlrc.py
Last active March 4, 2023 10:10
download from music.163.com
import eyed3
import re
import glob
def get_lyric(lrc):
text = open(lrc).read()
text = re.sub(r'(?:\[.*\])+', '', text).strip()
text = map(lambda l: l.strip(), text.split('\n'))
ans = []
for l in text:
@scturtle
scturtle / simplex.py
Created July 6, 2013 12:01
simplex algorithm
from __future__ import division
try:
from numpypy import *
except ImportError:
from numpy import *
class Tableau:
def __init__(self, obj):
self.obj, self.rows, self.cons = obj, [], []
@nodesocket
nodesocket / bootstrap.flatten.css
Last active April 1, 2021 23:37
Below are simple styles to "flatten" bootstrap. I didn't go through every control and widget that bootstrap offers, only what was required for https://commando.io, so your milage may vary.
/* Flatten das boostrap */
.well, .navbar-inner, .popover, .btn, .tooltip, input, select, textarea, pre, .progress, .modal, .add-on, .alert, .table-bordered, .nav>.active>a, .dropdown-menu, .tooltip-inner, .badge, .label, .img-polaroid {
-moz-box-shadow: none !important;
-webkit-box-shadow: none !important;
box-shadow: none !important;
-webkit-border-radius: 0px !important;
-moz-border-radius: 0px !important;
border-radius: 0px !important;
border-collapse: collapse !important;
background-image: none !important;