This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup(){ | |
pinMode(4, OUTPUT); | |
pinMode(5, INPUT); | |
Serial.begin(9600); | |
} | |
void loop(){ | |
int length = pulseIn(5, HIGH); | |
Serial.println(length); | |
if(length < 1500) digitalWrite(4, LOW); // range is about 1000-2000 microseconds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int angle = 0; | |
int redState = 0; | |
void setup() { | |
pinMode(0, OUTPUT); | |
pinMode(1, OUTPUT); | |
pinMode(2, OUTPUT); | |
} | |
void loop() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <util/delay.h> | |
// Some serial comms stuff; just using for debugging | |
#include "uart.h" | |
typedef unsigned char byte; | |
byte spi(byte b); // Send / receive one byte over SPI | |
void sd_select(int high); // Set SD CS pin high or low |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Encoding: utf-8 | |
def find_exact str, node | |
if str == "" | |
return true | |
elsif !node[str[0]] | |
return false | |
else | |
return find_exact(str[1..-1], node[str[0]]) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Basic for loop:\n-------------------------") | |
t = {'a','b','c','d','e'} | |
for i, v in ipairs(t) do | |
print(i,v) | |
end | |
-------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Encoding: utf-8 | |
# The world's worst string singularize function, because | |
# Strive doesn't supply active_support | |
class String | |
def singularize | |
if self[-1] == 's' | |
return self[0..-2] | |
else | |
return self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To demo in irb: | |
# load 'spinner.rb' ; include Spinner ; spinner_demo | |
# | |
# To use, include this module in a class and then wrap something in with_spinner | |
# It has two params, both optional. See spinner_demo for usage examples. | |
module Spinner | |
def with_spinner total=nil, message="Working...", &blk | |
current=0 | |
shown=buildstr(message,current,total) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
importClass(Packages.java.sql.DriverManager); | |
importClass(Packages.java.sql.ResultSet); | |
// Let the classloader see it. | |
new Packages.com.mysql.jdbc.Driver(); | |
var DB_BASE='kingdom'; | |
var DB_USER='root'; | |
var DB_PASS=''; | |
var DB_HOST='localhost'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function monkeyRow(diff,max,op){ | |
var a=1; | |
var b=a+diff; | |
var ret=[]; | |
while(b<=max){ | |
ret.push(op(a,b)); | |
a++; | |
b++; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
importClass(Packages.javax.swing.JComponent); | |
importClass(Packages.javax.swing.JFrame); | |
importClass(Packages.javax.swing.JLabel); | |
importClass(Packages.java.awt.Color); | |
var frame=new JFrame('Foo!'); | |
var comp=new JComponent(){ | |
paintComponent:function(g){ | |
print('painted'); | |
g.setColor(Color.RED); |
OlderNewer