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
var template = function(template, model) { | |
for(var p in model) { | |
if( model.hasOwnProperty(p) ) { | |
var re = new RegExp( "#{" + p + "}", "ig" ); | |
template = template.replace(re, model[p]); | |
} | |
} | |
return template; | |
}; | |
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('Worker', function(){ | |
var helpers = require('./test_helpers'); | |
var loadModule = require('./module-loader').loadModule; | |
var mocks = require('mocks'); | |
var assert = require("assert"); | |
var module, fsMock, mockRequest, mockResponse, Worker; | |
Function.prototype.after = function(ms) { | |
var current = this; |
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 BlogPostImporter | |
@@subclasses = { } | |
def self.create type | |
c = @@subclasses[type] | |
if c | |
c.new | |
else | |
raise "Bad importer type: #{type}" | |
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
var queue = new (function(undefined){ | |
var _q = [], _size = 0; | |
this.push = function(task) { | |
_q.push(task); | |
_size++; | |
return task; | |
}; | |
this.next = 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
public class GithubController : Controller | |
{ | |
/// <summary> | |
/// Github OAuth Callback | |
/// </summary> | |
/// <param name="code"></param> | |
/// <returns></returns> | |
public JsonResult callback(string code) | |
{ | |
var clientId = "[insert yours]"; |
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
[ElmahHandleError] | |
public partial class ProjectsController : Controller | |
{ | |
private IProjectService _projectService = null; | |
public ProjectsController () : this( null, null ) { } | |
public ProjectsController ( IProjectService projectService ) | |
{ | |
_projectService = projectService; | |
} |
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
using System; | |
using System.Collections.Generic; | |
using System.Dynamic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Newtonsoft.Json; | |
namespace AWordAboutDynamic |
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
public class WeaponBase : IWeapon | |
{ | |
private static WeaponBase _instance; | |
public static WeaponBase Instance() | |
{ | |
var lockObj = new Object(); | |
if ( _instance == null ) | |
{ | |
lock ( lockObj ) | |
{ |
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
def find(since=nil, til=nil) | |
@where << since ? " AND C.time >= #{since}" : "" | |
@where << til ? " AND C.time <= #{til}" : "" | |
find_by_sql make_sql #assume this generates SQL statement using @where and some other stuff... | |
end | |
# Question 1: Why does the above fail with this error: | |
# TypeError: can't convert nil into String | |
# from (irb):3:in `<<' |
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
(1..100).each do |i| | |
out = i%3 != 0 && i%5 != 0 ? i : "" | |
puts "#{out}#{ 'FIZZ' if i%3 == 0 }#{ 'BUZZ' if i%5 == 0 }" | |
end |