Skip to content

Instantly share code, notes, and snippets.

View ashaindlin's full-sized avatar

Alex Shaindlin ashaindlin

View GitHub Profile
@ashaindlin
ashaindlin / twidge-reply-to-last-tweet.sh
Created May 6, 2014 20:25
Reply to your own previous tweet using twidge.
#!/bin/bash
# Script to reply to your own previous tweet. Useful for those long
# conversations we know you like to have with yourself.
last_tweet_id=$(twidge lsarchive -l | head -1 | cut -f 1)
twidge update -i $last_tweet_id
@ashaindlin
ashaindlin / polyxpoly.m
Created May 19, 2014 14:22
Run polyxpoly without Mapping Toolbox installed
% Download intersections.m from http://www.mathworks.com/matlabcentral/fileexchange/11837-fast-and-robust-curve-intersections
% and put it in a folder on your MATLAB path. Put this function on your path too.
function [xi, yi] = polyxpoly(x1, y1, x2, y2)
[xi, yi] = intersections(x1, y1, x2, y2);
end
@ashaindlin
ashaindlin / label.py
Last active August 29, 2015 14:04
Discern which elements of a tree are leafs and which are nodes, given only preorder and postorder traversals
print """Sample tree:
_1_
/ | \\
2 3 4
/ \\ \\
5 6 7
/ \\ \\
8 9 10
"""
@ashaindlin
ashaindlin / vm.sh
Last active August 29, 2015 14:04
Start MINIX on QEMU VM in background, SSH to it
#!/bin/bash
# Start the VM with `./vm start` (to boot from disk) or `./vm livecd` (to boot
# from installation media). Once openssh starts on the VM, the QEMU console will
# display something like:
#
# Local packages (start): sshd Starting sshd. done.
#
# Now you can ssh to the VM from your host machine with `./vm ssh`.
#
# To kill the VM, run `./vm kill`. This might do something surprising and
@ashaindlin
ashaindlin / quit-when-empty.js
Created August 6, 2014 16:05
Proof-of-concept thing for a twitterbot that doesn't repeat words
var fs = require('fs');
function go() {
fs.readFile('./unused.txt', function(err, data) {
if (err) throw err;
var items = data.toString().split('\n');
var index = Math.floor(Math.random()*items.length);
var item = items[index];
items.splice(index, 1);
console.log(item);
@ashaindlin
ashaindlin / mkdir_and_cd.sh
Last active August 29, 2015 14:04
Seriously, stop typing `cd $_`
#!/bin/sh
# The alias to call this script needs to source it, not just execute it in a
# new shell, or you'll make the directory but not cd to it in the parent shell.
# Like this: alias mcd='source ~/.scripts/mkdir_and_cd.sh'
if [ "$#" -ne 1 ]; then
echo "Please pass exactly one directory name."
else
mkdir "$1"
cd "$1"
@ashaindlin
ashaindlin / main.py
Last active August 29, 2015 14:04
Thue-Morse sequence generator using horribly inefficient string operations
def thuemorse(n):
b = { "0": "1", "1": "0" }
s = "0"
print "0\t0"
for i in range(1, n+1):
print "{}\t".format(i),
s += ''.join([b[x] for x in s])
print s
if __name__ == '__main__':
@ashaindlin
ashaindlin / generate-password.sh
Last active August 29, 2015 14:05
Generate random passwords (r/dailyprogrammer Easy #4)
#!/bin/sh
# Generate random passwords. Usage: `./generate-password.sh [quantity [length]]`
case "$#" in
0)
QUANTITY=1
LENGTH=32
;;
1)
QUANTITY="$1"
@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])
@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