Skip to content

Instantly share code, notes, and snippets.

View kzar's full-sized avatar
🐈
Bashing the rocks together...

Dave Vandyke kzar

🐈
Bashing the rocks together...
View GitHub Profile
; Problem 1
(apply + (filter #(or (= 0 (mod % 5)) (= 0 (mod % 3))) (range 1000)))
; Problem 2
(defn fib
([] (fib 0 1))
([n-2 n-1]
(lazy-seq (cons n-1 (fib n-1 (+ n-2 n-1))))))
(reduce + (take-while #(< % 4000000) (filter even? (fib))))
@kzar
kzar / fb_helpers.py
Created October 14, 2010 13:34 — forked from droot/fb_helpers.py
Stuff that's missing from the Facebook python SDK
import base64
import hashlib
import hmac
import simplejson as json
def base64_url_decode(inp):
padding_factor = (4 - len(inp) % 4) % 4
inp += "="*padding_factor
return base64.b64decode(unicode(inp).translate(dict(zip(map(ord, u'-_'), u'+/'))))
@kzar
kzar / tetris.rb
Created December 16, 2010 16:19
Tetris in Ruby (Dave's first Ruby program)
#!/usr/bin/env ruby
# Dave's Tetris clone, Dave Barker 2010
# (Requires rubygame, rsdl, sdl, sdl_graphics, sdl_ttf and ruby >= 1.9)
# (Make sure you put Chalkduster.ttf if working directory)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
@kzar
kzar / gem-install-rice-output
Created January 24, 2011 17:13
gem install rice output
kzar@discodave:~/iris/iris-protocol-auth$ gem install rice
Building native extensions. This could take a while...
ERROR: Error installing rice:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-1.9.1-p378/bin/ruby extconf.rb
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
@kzar
kzar / rails + pretty_json
Created March 25, 2011 14:12
First, broken attempt at getting prettier JSON back from Rails 3
#config/initializers/pretty_json.rb
module ActiveRecord
class Base
def to_json
JSON.pretty_generate(as_json)
end
end
end
@kzar
kzar / rs-send-python.py
Created May 12, 2011 15:08
Script to automate Python deployment to Telit GPS unit
#!/usr/bin/python
# Script to send Python scripts to the Round solutions development board
# (Designed for use with the GSM862-GPS and RS-EB-S3 Rev 3)
#
# Idea is that you connect to the Unit through the serial port provided
# using the screen command. You then use this script to have the commands
# and your code sent to screen automatically.
# (For help with screen read this:
# http://www.tigoe.net/pcomp/resources/archives/avr/000749.shtml )
@kzar
kzar / telit-pyo.py
Created May 22, 2011 12:05
Script to dump .pyo files from Telit 862 over serial as hex
#
# Script to dump all pyo's on a Telit 862GPS over the serial port as hex.
# (Useful as the unit takes SO long to compile .pyo's.)
#
#
# Copyright 2011 Dave Barker
#
**** MOVED https://github.com/kzar/telit-862-python-tools ****
@kzar
kzar / decode-telit-pyo.py
Created May 22, 2011 12:48
Script to check and write out hex dumped .pyo files from Telit 862
#!/usr/bin/python
# Script to write pyo files from dump provided by telit-pyo.py script
# - Expects format provided by telit-pyo.py
# https://gist.github.com/985401
# - Prepends 'telit-' to file names
# - Verifies sizes match what the unit reported before writing
#
# Copyright 2011 Dave Barker
#
@kzar
kzar / ajax.clj
Created October 25, 2011 12:14
Clojure scraper - java.lang.OutOfMemoryError: Java heap space
(ns logs.views.ajax
(:import java.net.URL)
(:require [logs.views.common :as common]
[noir.content.pages :as pages]
[net.cgrand.enlive-html :as html]
[clj-time.core :as time]
[clj-time.format :as time-format])
(:use [clojure.string :only [trim]]
[noir.core]
[hiccup.core]
@kzar
kzar / gist:1322092
Created October 28, 2011 11:27
CouchDB error thrown when inserting around 8 megs of JSON
[Wed, 26 Oct 2011 17:23:23 GMT] [info] [<0.13767.0>] 127.0.0.1 - - 'PUT' /ertoc/2c88db6ce6159cab69e6b007f4000eec?rev=8-aa880aa6de953cf56ce3deb0ab991fe1 201
[Wed, 26 Oct 2011 17:23:25 GMT] [error] [<0.13797.0>] OS Process Error <0.3932.0> :: {os_process_error,{exit_status,0}}
[Wed, 26 Oct 2011 17:23:25 GMT] [error] [emulator] Error in process <0.13797.0> with exit value: {{nocatch,{os_process_error,{exit_status,0}}},[{couch_os_process,prompt,2},{couch_query_servers,'-map_docs/2-fun-1-',2},{lists,map,2},{couch_query_servers,map_docs,2},{couch_view_updater,view_compute,2},{couch_view_updater...
[Wed, 26 Oct 2011 17:23:25 GMT] [error] [<0.3655.0>] ** Generic server <0.3655.0> terminating
** Last message in was {'EXIT',<0.13794.0>,