This file contains 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 static class EvilStringHelper | |
{ | |
private static readonly Action<string, int, char> _setChar; | |
private static readonly Action<string, int> _setLength; | |
static EvilStringHelper() | |
{ | |
if (Environment.Version.Major < 4) | |
{ | |
MethodInfo setCharMethod = typeof(string).GetMethod( |
This file contains 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
function eachAsync(collection, iterator, callback) { | |
var iterate = function(i) { | |
setTimeout(function() { | |
iterator(collection[i]); | |
if (i < collection.length) { | |
iterate(i + 1); | |
} else { | |
callback(); | |
} | |
}, 0); |
This file contains 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
import sublime | |
import sublime_plugin | |
class NumberCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
selection = self.view.sel() | |
for region in selection: | |
try: | |
value = int(self.view.substr(region)) | |
self.view.replace(edit, region, str(self.op(value))) |
This file contains 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
function throttle(callback, delay, before) { | |
var busy = false; | |
var hold = false; | |
function callAfterDelay(self, args) { | |
setTimeout(function() { | |
if (hold) { | |
hold = false; | |
callAfterDelay(self, args); | |
return; |
This file contains 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
Show hidden characters
[ | |
{ "keys": ["ctrl+alt+r"], "command": "randomize" } | |
] |
This file contains 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 yield to create a generator -- only possible in ES6/Harmony. | |
*/ | |
function fibonacci(limit) { | |
var fn1 = 1; | |
var fn2 = 1; | |
while (1) { | |
var current = fn2; | |
fn2 = fn1; | |
fn1 = fn1 + current; |
This file contains 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
require 'nokogiri' | |
file = ARGV[0] | |
if !File.exist?(file) | |
puts "File #{file} does not exist." | |
exit | |
end | |
html = File.read(file) |
This file contains 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
function Agent(name) { | |
this.name = name; | |
this.command = function(subordinate, description, instructions) { | |
console.log(this.name + " tells " + subordinate.name + ": '" + description + "'"); | |
instructions.apply(subordinate); | |
}; | |
this.getCoffee = function() { | |
var recipients = Array.prototype.slice.call(arguments); |
This file contains 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
# Disable XML parameter parsing completely as a stopgap measure until upgrading to Rails 2.3.16 | |
# to defend against arbitrary code execution vulnerability; see: | |
# https://groups.google.com/forum/#!topic/rubyonrails-security/61bkgvnSGTQ/discussion | |
ActionController::Base.param_parsers.delete(Mime::XML) |
This file contains 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.Text; | |
namespace FastStringConcatenation | |
{ | |
public class FastString | |
{ | |
const int DefaultCapacity = 32; | |
readonly StringBuilder buffer; |
NewerOlder