Skip to content

Instantly share code, notes, and snippets.

@forforf
forforf / stringify_hash.rb
Created August 21, 2012 21:11
Stringify Ruby Hash - One Liner
#From Sarah Mei
# http://stackoverflow.com/questions/800122/best-way-to-convert-strings-to-symbols-in-hash
my_hash.inject({}){|memo,(k,v)| memo[k.to_s] = v; memo}
#To convert to symbols
my_hash.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
@forforf
forforf / library_boilerplate.js
Created September 12, 2013 13:32
Javascript Library Template
window.FooFoo = (function () {
//Private Functions & Classes
function notExposed () { /* internal library logic */ }
//Public Exposed Object
var FooFoo = {
//publicly available as FooFoo.static
static: "Some static value",
doSomething: function () { ... publicly available as FooFoo.doSomething ... }
class Cloner
def clone_array_of_hashes(a)
a.map{|h| h.clone}
end
end
@forforf
forforf / foo.rb
Created March 7, 2013 22:32
RSpec issue with Regex declared by let
class Foo
def a_string
"abcdef8"
end
end
@forforf
forforf / Reqest2.java
Created December 5, 2012 21:59
Recommendations for Request.java based on test results
//This passes all but one test
package src;
// Had to include these
import java.util.Map;
import java.util.HashMap;
class Request {
public static final String NOCODE = "NOCODE";
@forforf
forforf / deferred_arrray.coffee
Created November 27, 2012 14:50
Using jQuery Deferred Promises with Arrays
makeButton = (id) ->
$("<button id=\"button#{id}\">Button #{id}</button>")
$ ->
$('#go').click (evt)->
$('#buttons').empty()
$("#messages").empty()
qty = parseInt $('#qty').val()
qty = 1 if qty < 1
buttons = (makeButton(i) for i in [0..qty-1])
@forforf
forforf / manual_spine.txt
Created October 2, 2012 16:14
Integrating Spine Model
model name: post
Rails
1. scaffold rails controller post
2. add resource :posts to config/routes.rb
3. delete any views in views/posts EXCEPT for index
4 .replace index content with just qQuery loader (in haml)
#app
:javascript
jQuery(function(){
@forforf
forforf / android-myhandlerthread.java
Created July 25, 2012 17:43
Android - Custom Handler Thread
//Note that this mostly duplicates Android's HandlerThread class
// so that one might be a better choice
// The only thing this one has going for it is that the handler is part
// of the thread instance, but this may not be as flexible.
public class MyHandlerThread extends Thread {
private static final String TAG = "MyThread";
public Handler mHandler;
private static int thrCount = 1;
@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;