Skip to content

Instantly share code, notes, and snippets.

@corycook
corycook / wait.js
Created April 24, 2018 17:35
A simple promised wait utility.
function wait(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
@corycook
corycook / throttle.js
Created April 24, 2018 17:34
A simple throttle function.
function throttle(fn) {
let waiting = false;
return function() {
if (!waiting) {
waiting = true;
requestAnimationFrame(() => {
waiting = false;
fn.apply(this, arguments);
});
}
@corycook
corycook / debounce.js
Last active March 19, 2019 20:39
A really simple debounce function.
function debounce(fn, ms) {
let id;
return function() {
clearTimeout(id);
id = setTimeout(() => fn.apply(this, arguments), ms);
}
}
@corycook
corycook / amd.js
Created January 14, 2016 03:38
A quick implementation of AMD
(function () {
var filename = "amd.js";
var scripts = Array.prototype.slice.call(document.querySelectorAll("script[src]"));
var self = scripts.filter(function (x) { return x.getAttribute("src").indexOf(filename) > -1; })[0];
var src = self.getAttribute("src");
var root = src.substring(0, src.indexOf(filename));
var modules = {};
@corycook
corycook / fn.js
Last active March 19, 2019 20:40
JavaScript function type checking and overloading
function create() {
var types = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
var body = arguments[arguments.length - 1];
return function () {
if (arguments.length < types.length)
throw new Error("Argument count mismatch.");
for (var i = 0; i < types.length; i++) {
if (arguments[i].constructor != types[i] && !(arguments[i] instanceof types[i]))
throw new Error("Argument type mismatch. (" + types[i].name + ")");
@corycook
corycook / enumerable.js
Created October 29, 2015 23:57
Using Object.defineProperty to fake an Array-like object that can be iterated over with a for loop or Array.prototype.slice.
function Enumerable(generator, length, start) {
this.generator = generator;
this.length = length || Infinity;
this.current = start || 0;
this.index = 0;
Object.defineProperty(this, this.index, { get: this.next, configurable: true });
}
Enumerable.prototype.next = function() {
@corycook
corycook / HtmlHelperExtensions.cs
Last active August 29, 2015 14:25
C# Web MVC BeginActionLink
using System.Collections.Generic;
using System.Web.Mvc;
namespace TestWeb.Extensions
{
public static class HtmlHelperExtensions
{
static Dictionary<string, object> ToDictionary(object o)
{
return o.GetType().GetProperties().ToDictionary(n => n.Name, n => n.GetValue(o, null));
@corycook
corycook / frida-modules.py
Last active February 5, 2020 11:40
Command line shortcut to enumerate modules with frida
import frida, argparse
parser = argparse.ArgumentParser(description='List modules for a process')
parser.add_argument('process_names', metavar='process name', nargs='+', help='names of processes to enumerate')
parser.add_argument('-R', dest='target', action='store_const', const=True, default=False,
help='target remote device')
try:
args = parser.parse_args()
target = frida