Skip to content

Instantly share code, notes, and snippets.

@calebsmith
calebsmith / gist:98697ccc5ad81c103b1c
Created March 23, 2015 17:49
Django Sports App Project Steps
1. Project structure ( mkvirtualenv, startproject, startapp)
2. commit
3. Models - makemigrations, migrate
4. Admin
5. Enter in example data.
6. Views, Urls, a skeleton of templates. (extends base.html)
7. Commit
8. Templates (focus on variables)
9. Commit
OViiiiiiVViii***:****::*********iiiiiiiiiiiVVViiViiiVVViVViVVVVVVVVVVVVVVVVVVVVV
iiiVViiiiiiii***:****:****i*****iiiiiiiiViiiiViViVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
iiiiViiiiiiii********::*:********iiiiiiiiiiiVViiVVVVVVVVVVVVVVVVVVVVVVViiiiiiiVV
iiiiiiiiiiiii********:::*******i***iiiiiiiiiViVVVVVViVVVVViiiiiiiiiiiiiiiiiiiiiV
ii*iiiiiiiiii*VV*****::*:::*****VEEEEOViiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
ii*iiiiiiiiiiii*****:::*:***VEOEEMMEMMEEEEViiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
VViiiiiiiiiiiii****:::::::*EOEEEEEEEEEEOEEEEiiiiiiiiiiiiiiiiiiiiiiiiiiiii*iiiiii
iiiiiiiiiiii*i*****::::::*OEEEEEEOVOEOEVVEEEMiiiiiiiiiiiiiii*iiiiii*ii*iiiiiiiii
iiiiiiiiiiiiiiii***::::::OEEEOOVOi~:*i:::iEEiOiiiiii*********iiiiiiiiii*ii*iiiii
iiiiiiiiiiiiii****:::::::OEME**::::~::***:VEVOi*i****i*******iii*iiiii**ii*iiiii
@calebsmith
calebsmith / gist:750d599bb811913999e9
Created February 6, 2015 14:01
Playing with SKI and Y combinators in Erlang
-module(funs).
%%% SKI combinators
i(X) -> X.
k(X) ->
fun(F) -> X end.
s(F) ->
fun(G) ->
@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)))
@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: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 / 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 / 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
DEFSNG A-Z
CLS
SCREEN 12
xp = 320
yp = 240
num = 12
DO
cad = 360 \ num
@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