Skip to content

Instantly share code, notes, and snippets.

n=int(input("base"))
def triangle(n):
y=((n+(n-1))/2)
x=1
while (x <= n):
if x%2==0:
print(" "*(y+1)+"* "*(x-1)+"*")
x=x+1
y=y-1
@Satshabad
Satshabad / bf.clj
Created September 30, 2014 04:54
Brainf*ck interpreter in Clojure
(ns brainfart.core)
(defn- inc-at
[tape ptr]
(update-in tape [ptr] #(+ % (byte 1))))
(defn- dec-at
[tape ptr]
(update-in tape [ptr] #(- % (byte 1))))
@Satshabad
Satshabad / gist:6d224e15046dd80711d4
Last active August 29, 2015 14:06
Satshabad's vimrc
set nocompatible " be iMproved
filetype off " required!
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'
Bundle 'chrisbra/NrrwRgn'
@Satshabad
Satshabad / gist:cb8db31f6a92421497e8
Created August 20, 2014 23:58
Linearly scale a value in clojure
(defn- scale-value
"Linearly transforms x from range input-range to output-range where:
input-range - a vector like [min max]
output-range - a vector like [min max]
"
[x input-range output-range]
(let [[a b] input-range
[c d] output-range]
(defn permutations [elements]
(if-let [xs (seq elements)]
(for [x xs
permutation (permutations (remove #{x} xs))]
(conj permutation x))
[[]]))
@Satshabad
Satshabad / beautiful.js
Created August 23, 2013 08:12
This took me a while
function isLoggedIn() {
var deferred = $q.defer();
Facebook.getLoginStatus().then(function(loginStatus) {
if (!loginStatus.loggedIn) {
resolve(deferred, false);
} else {
@Satshabad
Satshabad / gist:5978558
Created July 11, 2013 19:40
My *special* zen of python
python -m this | awk 'NR>=3&&NR<=9' | awk -F " " '{t=$1;$1=$NF;$NF=t}1' | awk '{print tolower($0)}' | sed -e 's/\([[:punct:]]\)//g' | awk '{print toupper(substr($0,1,1))""substr($0,2)}'
@Satshabad
Satshabad / gist:5606308
Created May 19, 2013 01:26
Pipe vim ranges into a new buffer, and filter that, and then filter that
silent %y | new | silent pu | %!grep db ^@ %!column -t
@Satshabad
Satshabad / gist:5373251
Created April 12, 2013 16:24
How to tune a single guitar
First tune the bottom E. string to a tuning fork or tuning machine. Next, fret the E. string at the tenth fret. This will give you a D. Tune the D. string to this note by ear. Next, fret the D. string at the fifth fret. Tune the G. string to the D. string at the fifth fret. Now fret the G. string at the second fret. This gives you an A. Tune the A. string from this note. Now fret the A. string at the second fret. Tune the B. string from this note. It will be an octave up. Next, fret the D. string at the second fret. This gives you E. Tune your high E from this. Again this will be an octave.
@Satshabad
Satshabad / gist:5022019
Created February 24, 2013 00:25
Small script to mute your volume for a small amount of time and then unmuting. Useful for beating Spotify ads.
import time
import subprocess
import re
start_time = int(time.time())
cmd = ['amixer', 'get', 'Master']
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)