Skip to content

Instantly share code, notes, and snippets.

{
"metadata": {
"name": "Untitled1"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@calebsmith
calebsmith / gist:8578779
Created January 23, 2014 13:57
Simple ping/pong Erlang program
-module(ping_module).
-export([start/1, ping/2, pong/1, ending_timer/0]).
ping(0, Pong_PID) ->
Pong_PID ! finished,
io:format("ping finished~n", []);
ping(N, Pong_PID) ->
io:format("Sending ping~n", []),
Pong_PID ! {ping, self()},
@calebsmith
calebsmith / piano.scm
Created January 30, 2014 05:02
First pass at Weechat plugin to control pianobar (CLI Pandora/Last.fm client)
(use-modules (ice-9 popen))
(weechat:register "piano" "MCConsALot" "0.1" "GPL3" "Control piano bar client" "" "")
(weechat:hook_command
"piano" "Control pianobar"
"[command]" "command to send to pianobar. Use /piano start, to begin"
"start next quit station send"
"main-command-handler" "")
@calebsmith
calebsmith / gist:9590323
Created March 16, 2014 21:41
html -> markdown with sed
# A sed script to convert HTML slides for reveal.js to markdown
# Assumes @@@\n is used for slide separator, and Note: is used for slide notes
#
# N.B. - Don't use regexes for HTML...ever. This is just a quick intro to sed
# and works for 90% of my needs for slides written in HTML (well-formed). This
# breaks pretty crazily for nested HTML
#
# Usage:
# sed -f thisfilename filename.html > filename.md
/^ *$/d
DEFSNG A-Z
CLS
SCREEN 12
xp = 320
yp = 240
num = 12
DO
cad = 360 \ num
@calebsmith
calebsmith / counter.py
Created August 7, 2014 04:04
Python talk
#!/usr/bin/python
"""
A program that counts the number of occurences of words in a file.
Plain text books without copyright can be obtained from Project Gutenberg:
http://www.gutenberg.org/
run 'python counter.py' to see the number of occurrences of the top 200
most commonly used words
@calebsmith
calebsmith / android_helpers.sh
Last active August 29, 2015 14:06
Command-line Android Build Sanity
#!/bin/bash
function android_get_pkg() {
# Gets the name of the package
echo $(aapt dump badging $1 |
awk -F" " '/package/ {print $2}' |
awk -F"'" '/name=/ {print $2}'
)
}
@calebsmith
calebsmith / gist:77f373bf7e3b4db84436
Last active August 29, 2015 14:07
Reindex JP2 Homepage content
from datetime import datetime
from django.db.models import get_model
from django.contrib.sites.models import Site
def reindex_homepage(site_id=2010, num=50, async=False):
layout_ids = find_homepage_layout_ids(site_id)
return reindex(layout_ids, num, async)
@calebsmith
calebsmith / gist:13c3c36737fdb98eb553
Created November 20, 2014 14:31
Rough Polynomial Calculator with Derivatives
(define (repeat num arg)
(let inner ((current 0))
(if (>= current num)
#nil
(cons arg (inner (1+ current))))))
(define (make-range-stream min-x max-x step-x)
(let inner ((x min-x))
(cons x (delay
(if (or (eq? x #nil) (>= (+ step-x x) max-x))
@calebsmith
calebsmith / gist:89c6fe64e865704f5105
Last active August 29, 2015 14:13
Best fit using least-squares estimation in Scheme
(define (best-fit points)
;; Use least-squares estimation to find best fit line for given set of points
(let* ((sumx (apply + (map car points)))
(sumy (apply + (map cadr points)))
(sumxy (apply + (map (lambda (p) (* (car p) (cadr p))) points)))
(sumx2 (apply + (map (lambda (p) (* (car p) (car p))) points)))
(n (length points))
(slope (/ (- sumxy (/ (* sumx sumy) n)) (- sumx2 (/ (* sumx sumx) n))))
(y-int (/ (- sumy (* slope sumx)) n)))
(cons slope y-int)))