Skip to content

Instantly share code, notes, and snippets.

View ashaindlin's full-sized avatar

Alex Shaindlin ashaindlin

View GitHub Profile
@ashaindlin
ashaindlin / stitchpercent.py
Created July 26, 2017 08:30
Calculate how far along you are in a knitting project, assuming linear rate of increases
#!/usr/bin/env python3
def calculate(castOn: int, bindOff: int, totalRows: int, curRow: int):
incPerRow = (bindOff - castOn)/totalRows; # stitches increased per row
totalStitches = sum([castOn + incPerRow*r for r in range(1, totalRows)])
stitchesKnit = sum([castOn + incPerRow*r for r in range(1, curRow)])
return int(100 * stitchesKnit / totalStitches)
if __name__ == "__main__":
c = int(input("Stitches cast on: "))
@ashaindlin
ashaindlin / perun.sty
Created September 29, 2016 07:48
my LaTeX custom macros file as of 29.09.2016
\ProvidesPackage{perun}[2016/09/23 v0.1 My own macros]
% http://tex.stackexchange.com/questions/11890/where-to-put-a-custom-macros-file
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[gen]{eurosym}
\usepackage{enumitem}
\usepackage{siunitx}
\usepackage{mathtools} % provides dcases* environment in math mode
@ashaindlin
ashaindlin / gist:c548baca0e663b53dfbd
Last active October 2, 2015 00:49 — forked from mxgrn/gist:663933
Git's pre-commit hook to remove trailing whitespaces/tabs
#!/bin/sh
#
# This will abort "git commit" and remove the trailing whitespaces from the files to be committed.
# Simply repeating the last "git commit" command will do the commit then.
#
# Put this into .git/hooks/pre-commit, and chmod +x it.
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
@ashaindlin
ashaindlin / gist:7a43f4ce6f6a298638c2
Last active August 29, 2015 14:23
Tail recursion in the Racket repl
Welcome to Racket v5.3.6.
-> (define (factorial-no-tail n)
(if (= n 0)
1
(* n (factorial-no-tail (- n 1)))))
-> (require racket/trace)
-> (trace factorial-no-tail)
-> (factorial-no-tail 6)
>(factorial-no-tail 6)
> (factorial-no-tail 5)
@ashaindlin
ashaindlin / abstract-integers.rkt
Last active August 29, 2015 14:23
Static analysis of signed integer addition and multiplication in Racket (see http://matt.might.net/articles/intro-static-analysis/)
#lang racket
(require racket/set)
; elements in the abstract integers
(define S (set '+ 'o '-))
; Z -> S
(define (alpha z)
(cond
@ashaindlin
ashaindlin / i3status-2.9-no-sound.patch
Last active August 29, 2015 14:22
i3status 2.9 without audio
From 0237a9fb589cd11c5409f55c84e1fb1e4037516f Mon Sep 17 00:00:00 2001
From: Alex Shaindlin <me@ashaindlin.com>
Date: Tue, 26 May 2015 20:25:48 -0400
Subject: [PATCH] Remove everything audio-related
---
Makefile | 1 -
i3status.c | 22 -------
src/print_volume.c | 181 -----------------------------------------------------
3 files changed, 204 deletions(-)
@ashaindlin
ashaindlin / groupBy.hs
Created December 7, 2014 16:32
groupBy with a fold
myGroupBy :: (a -> a -> Bool) -> [a] -> [[a]]
myGroupBy p xs = foldr f v xs
where
v = []
f x ys = if (length ys > 0 && p x (head (head ys)))
then (x:(head ys)):(tail ys)
else [x]:ys
@ashaindlin
ashaindlin / ConvexHull.hs
Last active August 29, 2015 14:09
Graham scan for convex hull calculation (Real World Haskell Ch. 3 Exercises 10-13)
module ConvexHull where
import Data.List (sortBy, delete)
import Data.Ord (comparing)
data Direction = Left | Right | Straight
deriving (Show, Eq)
data Point = Point {
x :: Double,
@ashaindlin
ashaindlin / ch3-10.hs
Created August 15, 2014 02:49
Yet Another Haskell Tutorial Ch. 3 Exercise 10 - sum, product, and list of factorials
module Main
where
import System.IO
main = do
num <- getNums
putStrLn ("The sum is " ++ show (sum num))
putStrLn ("The product is " ++ show (product num))
putFactorials num
@ashaindlin
ashaindlin / daysuntil.py
Last active August 29, 2015 14:05
Days-until calculator (r/dailyprogrammer Easy #2)
#!/usr/bin/env python
import datetime, sys
today = datetime.date.today()
month = today.month
year = today.year
if len(sys.argv) == 2:
day = int(sys.argv[1])