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
| 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); | |
| } | |
| } |
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
| 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; |
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 |
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
| 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
| 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
| [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
| 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
| 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
| class BlogPostImporter | |
| @@subclasses = { } | |
| def self.create type | |
| c = @@subclasses[type] | |
| if c | |
| c.new | |
| else | |
| raise "Bad importer type: #{type}" | |
| end | |
| end |