Skip to content

Instantly share code, notes, and snippets.

View dydx's full-sized avatar
🎯
Focusing

Josh Sandlin dydx

🎯
Focusing
View GitHub Profile
@dydx
dydx / shortener_one_filer.rb
Created December 6, 2010 01:47
my Shortener.rb webapp in one file
# shortener.rb - Josh Sandlin - 12/5/2010 - 6:19PM
# Simple url shortener with Sinatra and OpenKeyVal.org
# "THE BEER-WARE LICENSE" (Revision 43):
# <joshua.sandlin@gmail.com> wrote this file. As long as you retain this
# notice you can do whatever you want with this stuff. If we meet some day,
# and you think this stuff is worth it, you can buy me a beer in return.
# ~Josh Sandlin
require 'rubygems'
@dydx
dydx / pe_7.lisp
Created December 29, 2010 00:58
SPOILER for Project Euler #7
; pe_7.lisp - Josh Sandlin - 12/28/2010
; Project Euler #7 - 10001st prime
; primality predicate function (from PCL ;)
(defun primep (number)
(when (> number 1)
(loop for fac from 2 to (isqrt number) never (zerop (mod number fac)))))
; array of primes
(defparameter *primes-list* (loop for i from 1 to 150000
@dydx
dydx / nifty-funs.lisp
Created December 30, 2010 04:08
excerpt from "nifty-funs.lisp"
(defun euler-totient (n)
"Returns the euler-totient, and the coprimes that count the totient
for any number n"
(let ((coprimes (loop for x from 1 to n when (= 1 (gcd x n)) collect x)))
(values (length coprimes) coprimes)))
(defun part-k-n (k n)
(let ((cache (make-hash-table :test #'equal)))
(labels ((aux (k n cache)
(multiple-value-bind (val win) (gethash (list k n) cache)
@dydx
dydx / ircbot.fs
Created January 10, 2011 00:33
simple irc bot in F#
#light
open System
open System.IO
open System.Net
open System.Net.Sockets
open System.Text.RegularExpressions
let server = "irc.enigmagroup.org"
let port = 6667
@dydx
dydx / creative_cursing.fs
Created January 11, 2011 23:59
based on a popular children's book
#light
open System
open System.IO
let getWordList file =
File.ReadAllLines( file )
let rnd = Random()
let getRandArrElement arr =
@dydx
dydx / I2C_Master_Reader.pde
Created November 30, 2011 04:15
Arduino I2C setup
// Running on an Arduino Mega2560 R.3
// #20 - SDA
// #21 - SCL
#include <Wire.h>
void setup() {
pinMode(13, OUTPUT);
Wire.begin();
Serial.begin(9600);
@dydx
dydx / accel_y_axis_led_swap.pde
Created December 10, 2011 22:54
illuminate left or right led with accelerometer tilt
/**
Two LEDs triggered by tilting of accelerometer
along Y axis.
Arduino Diecimila and Memsic 2125
*/
int ledPins[] = {6,7};
int yPin = 10;
int yRaw;
@dydx
dydx / base_station.pde
Created January 20, 2012 06:01
Hardware base station for reading climate data along with a nice Processing GUI for your viewing pleasure
#include <SHT1x.h>
#define dataPin 4
#define clockPin 5
SHT1x sht1x(dataPin, clockPin);
void setup() {
Serial.begin(9600);
}
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
typedef enum {BOOLEAN, FIXNUM, CHARACTER, STRING, THE_EMPTY_LIST, PAIR} object_type;
/***************** MODEL ******************/
typedef struct object {
@dydx
dydx / ping_calibrate.c
Created July 18, 2012 21:24
Calibrate and test a Parallax PING))) Sensor
#include <Ping.h>
Ping ping = Ping(12, 0, 0);
boolean is_calibrated = false;
float calibration_distance = 0.00;
float current_distance = 0.00;
int alarm_pin = 13;
// because my IO shield is fubar
// and has H/L mixed