Skip to content

Instantly share code, notes, and snippets.

@forforf
forforf / ternary_style.rb
Last active August 29, 2015 14:01
Ternary Style
# ternary approach
mood = day.is_sunny? ? 'good' : 'bad'
# if then else approach
mood = if day.is_sunny? then 'good' else 'bad' end
# boolean approach
mood = (day.is_sunny? && 'good') || 'bad'
# override approach
@forforf
forforf / angular_dependency_mocking.js
Created February 4, 2014 01:46
angular dependency mocking
describe('RepoFetcherRatings', function(){
beforeEach( function(){
// mock factory objects
var fetchMock = {
fetcher:function(){
//fake promise
var then = function(){
return [{}, {}, {}];
};
@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 / 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 / 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;