This file contains hidden or 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
# 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 |
This file contains hidden or 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
describe('RepoFetcherRatings', function(){ | |
beforeEach( function(){ | |
// mock factory objects | |
var fetchMock = { | |
fetcher:function(){ | |
//fake promise | |
var then = function(){ | |
return [{}, {}, {}]; | |
}; |
This file contains hidden or 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
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 ... } |
This file contains hidden or 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
class Cloner | |
def clone_array_of_hashes(a) | |
a.map{|h| h.clone} | |
end | |
end |
This file contains hidden or 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
class Foo | |
def a_string | |
"abcdef8" | |
end | |
end |
This file contains hidden or 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
//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"; |
This file contains hidden or 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
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]) |
This file contains hidden or 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
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(){ |
This file contains hidden or 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
#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} |
This file contains hidden or 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
//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; | |
NewerOlder