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 / gist:3207268
Created July 30, 2012 14:21
cache locking
lock( HttpRuntime.Cache )
{
var languages = (Dictionary<string, string>)HttpRuntime.Cache.Get(languagesKey);
if (languages == null)
{
languages = new Dictionary<string, string>();
HttpRuntime.Cache.Add(languagesKey, languages, null, DateTime.Now.AddMinutes(15), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
}
}
@codeimpossible
codeimpossible / gist:3351974
Created August 14, 2012 19:25 — forked from jbubriski/gist:3207278
cache locking
private static readonly string _languagesKey = "languages";
public static Dictionary<string, string> GetLanguages()
{
return GetData(_languagesKey, () =>
{
// TODO: Get data from language service
var languages = new Dictionary<string, string>();
return languages;
(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
@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 `<<'
public class WeaponBase : IWeapon
{
private static WeaponBase _instance;
public static WeaponBase Instance()
{
var lockObj = new Object();
if ( _instance == null )
{
lock ( lockObj )
{
@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
@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 / 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 / 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 / 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