Skip to content

Instantly share code, notes, and snippets.

@forforf
forforf / android-events.java
Created July 25, 2012 12:38
Android - Events
//Touch Event
public boolean onTouchEvent(MotionEvent event) {
if (event != null) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Log.d(TAG, "Touch Event");
return true;
}
}
@forforf
forforf / android-callbacktask.java
Created July 24, 2012 23:06
Android - Callback Task, simple wrapper for pre and post execute
//Callback Tast
class CallbackTask implements Runnable {
private final Runnable task;
private final Callback callback;
CallbackTask(Runnable task, Callback callback) {
this.task = task;
@forforf
forforf / alpha.diff
Created May 18, 2012 02:35
Changes to default game to test alpha
//Added alpha to the red circle in circle template
re.e('circle align update')
.attr({
alpha: 0.3,
radius:10,
speed:15,
color:'#ff0000'
})
@forforf
forforf / so_example.rb
Created April 16, 2012 16:35
Barebones Sinatra App
post '/' do
session = login(params[:username], params[:password])
get_courses(session, params[:username])
erb :index
end
def login(username, password)
#login = Savon::Client.new($LOGIN_WSDL)
#login.http.auth.ssl.verify_mode = :none
@forforf
forforf / axlsx_bug.rb
Created April 3, 2012 17:51
Bug when styling cells when Range ends in zero.
require 'axlsx'
p = Axlsx::Package.new
wb = p.workbook
wb.styles do |s|
head = s.add_style :bg_color => "00", :fg_color => "FF"
wb.add_worksheet(:name => "Bug Example") do |sheet|
sheet.add_row ['This row should not be styled','but it is']
sheet.add_row ['The bug drops the trailing 0', 'so 10 -> 1']
sheet.add_row ['I havent tested to 100 rows', 'so not sure there']
sheet.add_row ['Row', '4']
@forforf
forforf / date_formats.coffee
Created March 6, 2012 15:27
Javascript/Coffeescript Date Formats
now = new Date();
alert now
alert now.toUTCString()
alert now.toJSON()
@forforf
forforf / get_ec2_address_for_putty.rb
Created November 8, 2011 21:39
Client side script for getting the address for an EC2 Instance
ssh_my_server.rb
require 'open-uri'
#not real names
Server = "MyServer"
bootstrap_data_json = open('http://my_iris.iriscouch.com/bootie/' + Server){|f| f.read}
bootstrap_data_raw = JSON.parse(bootstrap_data_json)
srv_name = bootstrap_data_raw["_id"]
@forforf
forforf / ec2_storing_its_address.rb
Created November 8, 2011 21:31
Server Script for populating a EC2 Name Server
require 'json'
#Get Instance IP Address
my_ip = `curl -s http://instance-data/latest/meta-data/public-ipv4`
#not real names
my_server_name = "MyServer"
bootstrap_db = "http://my_iris.iriscouch.com/bootie"
#url for the record data
record_loc = bootstrap_db + "/" + my_server_name
@forforf
forforf / wrap_require.rb
Created November 8, 2011 21:22
Wrapped Require
module Kernel
alias :old_req :require
def require(*args)
puts "Require called with: #{args}"
old_req *args
end
end
require 'pp'
@forforf
forforf / unbind_tap_bind.rb
Created October 28, 2011 02:52
Unbind, destroy and recreate a method at runtime. Meta-programming goodness
#This captures the Array#sort method and stores it in m
m = Array.instance_method(:sort)
#Shows that sort still works
[3,2,1].sort
#=> [1,2,3]
#Here we override the array sort method
#Array#sort no longer works
[3,2,1].class.send(:define_method, :sort){nil}