Skip to content

Instantly share code, notes, and snippets.

View codeimpossible's full-sized avatar
🍕
P I Z Z A

Jared Barboza codeimpossible

🍕
P I Z Z A
View GitHub Profile
@codeimpossible
codeimpossible / simple.template.js
Created October 8, 2012 15:44
very simple templating system in javascript
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;
};
@codeimpossible
codeimpossible / test_worker.js
Created October 4, 2012 03:42
BDD style unit tests for node-worker
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;
@codeimpossible
codeimpossible / blog_post_importer.rb
Created September 27, 2012 18:13
Factory pattern in Ruby
class BlogPostImporter
@@subclasses = { }
def self.create type
c = @@subclasses[type]
if c
c.new
else
raise "Bad importer type: #{type}"
end
end
@codeimpossible
codeimpossible / queue.js
Created September 26, 2012 01:56
simple queue data structure
var queue = new (function(undefined){
var _q = [], _size = 0;
this.push = function(task) {
_q.push(task);
_size++;
return task;
};
this.next = function() {
@codeimpossible
codeimpossible / Github OAuth ASP.Net MVC
Created September 20, 2012 15:19 — forked from abrudtkuhl/Github OAuth ASP.Net MVC
Github OAuth callback for ASP.Net MVC. Set yourapp.com/github/callback as the OAuth callback URL when you setup your application. If the users chooses to grant you permission, this controller/action get called to complete the transaction. See http://devel
public class GithubController : Controller
{
/// <summary>
/// Github OAuth Callback
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public JsonResult callback(string code)
{
var clientId = "[insert yours]";
@codeimpossible
codeimpossible / projectscontroller.cs
Created September 18, 2012 05:41
Found some old controller/service code
[ElmahHandleError]
public partial class ProjectsController : Controller
{
private IProjectService _projectService = null;
public ProjectsController () : this( null, null ) { }
public ProjectsController ( IProjectService projectService )
{
_projectService = projectService;
}
@codeimpossible
codeimpossible / gist:3741390
Created September 18, 2012 05:12
The simplest example of DynamicObject I could come up with...
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
public class WeaponBase : IWeapon
{
private static WeaponBase _instance;
public static WeaponBase Instance()
{
var lockObj = new Object();
if ( _instance == null )
{
lock ( lockObj )
{
@codeimpossible
codeimpossible / string_concat_eval.rb
Created August 29, 2012 18:05
<< evaluation in Ruby
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 `<<'
(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