Skip to content

Instantly share code, notes, and snippets.

View seadowg's full-sized avatar

Callum Stott seadowg

View GitHub Profile
@seadowg
seadowg / EventActivity.java
Created May 15, 2013 06:48
Cleaner (IMO) Event Handling in Android
// Standard way of hooking up Events:
public class EventActivity extends Activity {
public onCreate(Bundle savedInstanceState) {
findViewById(R.id.button_one).setOnClickListener(new View.OnClickListener) {
@Override
public void onClick(View view) {
Toast toast = Toast.makeText(EventActivity.this, "Clicked One!", Toast.LENGTH_SHORT);
toast.show()
}
@seadowg
seadowg / commit-msg
Created October 24, 2012 16:34
Append a random emoji commit-msg hook
#!/usr/bin/env ruby
emoji = [":bowtie:", ":smile:", ":laughing:", ":blush:", ":smiley:", ":relaxed:", ":smirk:", ":heart_eyes:", ":kissing_heart:", ":kissing_face:",
":flushed:", ":relieved:", ":satisfied:", ":grin:", ":wink:", ":wink2:", ":tongue:", ":unamused:", ":sweat_smile:", ":sweat:", ":weary:",
":pensive:", ":disappointed:", ":confounded:", ":fearful:", ":cold_sweat:", ":persevere:", ":cry:", ":sob:", ":joy:", ":astonished:", ":scream:",
":neckbeard:", ":tired_face:", ":angry:", ":rage:", ":triumph:", ":sleepy:", ":yum:", ":mask:", ":sunglasses:", ":dizzy_face:", ":imp:", ":smiling_imp:",
":neutral_face:", ":no_mouth:", ":innocent:", ":alien:", ":yellow_heart:", ":blue_heart:", ":purple_heart:", ":heart:", ":green_heart:", ":broken_heart:",
":heartbeat:", ":heartpulse:", ":two_hearts:", ":revolving_hearts:", ":cupid:", ":sparkles:", ":star:", ":star2:", ":dizzy:", ":boom:", ":collision:",
":anger:", ":exclamation:", ":question:", ":grey_exclamation:", ":grey_question:", ":zzz:", ":da
@seadowg
seadowg / frappuccino.coffee
Created August 13, 2012 01:13
Prototype FRP + Backbone collision
class Frappuccino.Backbone.Event extends Backbone.Event
event: (event_name) -> new Frappuccino.Event(this, event_name)
class Frappuccino.Event extends Backbone.Event
constructor: (origin, event) ->
@origin = origin
@event = event
@origin.bind(@event, (value) => this.occur(value))
@seadowg
seadowg / setup.txt
Created July 28, 2012 16:41
My Rails Setup
rails new <appname>
cd <appname>
git init
rm -r test
gem 'rspec-rails' -> Gemfile
bundle install
rails generate rspec:install
gem 'factory_girl_rails' -> Gemfile
@seadowg
seadowg / prodcon.scala
Created May 20, 2012 16:02
Producer/Consumer with Split Counting Semaphore in Scala
import actors.Actor._
val n = 8
val front = 0
val back = 0
val buffer = new Array[Int](n)
val full = new Semaphore(0)
val empty = new Semaphore(n)
// Producer
@seadowg
seadowg / Semaphore.scala
Created May 20, 2012 13:32
Semaphore implementation with Scala's synchronized
class Semaphore(private var count : Int) {
def p() {
synchronized {
while (count < 1) {}
count = count - 1
}
}
def v() {
synchronized {
@seadowg
seadowg / buildfile
Created March 13, 2012 19:07
Add growl 1.3 to buildr
# Add this to a buildr 'buildfile' to receive growl notifications when compilation
# completes or fails (including cc compilations)
require 'ruby_gntp'
# Growl setup
Buildr.application.on_completion do |title, message|
GNTP.notify({
:app_name => "buildr",
:title => title,
@seadowg
seadowg / echo.rb
Created February 12, 2012 16:18
Using echo in JRuby
include Java
require '$SCALA_HOME/scala-library.jar'
require 'lib/echo.jar'
include_class Java::com.github.oetzi.echo.core.Behaviour
include_class Java::com.github.oetzi.echo.core.Event
beh = Behaviour.new { | time | 5 }
event = Event.new
beh.at(1)
@seadowg
seadowg / map.java
Created December 5, 2011 00:05
HashMap built naively with TDD (and Tests)
// The following code is a series of test that were written in the order you'll read them. After
// each test was written it was run against the HashMap and the implementation was updated if it
// failed. The HashMap code is the final implementation that was built naively to pass each test.
// The Tests:
public class HashMapTest {
private HashMap map;
// Set up an empty map before each test
@seadowg
seadowg / Class.scala
Created November 26, 2011 21:53
`.class` in Scala
// I always run into massive problems when trying to write Scala that uses Java libraries. Recently
// one thing that threw me off was trying to do the following:
val class = MyAwesomeType.class
// This is often used in Java to get the 'Class' class for a class (yeah, I know). But how do we do
// this in Scala?
val class = MyAwesomeType.class // No. This reports that there is no 'class' member for the type