Skip to content

Instantly share code, notes, and snippets.

func swizzleReplacingCharacters() {
let originalMethod = class_getInstanceMethod(
NSString.self, #selector(NSString.replacingCharacters(in:with:)))
let swizzledMethod = class_getInstanceMethod(
NSString.self, #selector(NSString.swizzledReplacingCharacters(in:with:)))
guard let original = originalMethod, let swizzled = swizzledMethod else {
return
}
@kyle-ilantzis
kyle-ilantzis / whatwg-fetch.js
Last active April 6, 2017 19:15
React native fetch with timeout of 10 seconds
(function(self) {
'use strict';
if (self.fetch && self.fetch.hack) {
return
}
var TIMEOUT = 10000;
var support = {
@kyle-ilantzis
kyle-ilantzis / commander-tests.py
Last active October 9, 2015 21:37
Little helper for shell commands from python
import unittest
from commander import *
class TestCommander(unittest.TestCase):
def test_run(self):
r = run("ping", "localhost")
self.assertIsNone(r)
@kyle-ilantzis
kyle-ilantzis / option-versions-as-range.js
Last active October 7, 2015 02:56
nw-builder option.versions as a range
var semver = require('semver');
var NwVersions = require('nw-builder/lib/versions');
var nwDownloadUrl = 'http://dl.nwjs.io/';
function findNwVersion(version) {
return new Promise(function(resolve, reject) {
NwVersions.getVersions(nwDownloadUrl)
.then(function(versions) {
from multiprocessing import Pool
import polydivisible
def ppoly(ab):
a,b = ab
polydivisible.main(["polydivisible",str(a),str(b)])
def main():
with Pool(4) as p:
bs = zip(range(26,51),range(26,51))
module WriteManyInts where
import System.IO
import Control.Exception(bracket)
import qualified Data.Binary as Binary
import qualified Data.ByteString.Lazy as ByteString
writeManyInts name n
| n <= 0 = error "n <= 0"
| otherwise = bracket
@kyle-ilantzis
kyle-ilantzis / open-w-atom.reg
Last active June 1, 2021 17:20
Adds 'Open in Atom' to context menu in Windows Explorer.
Windows Registry Editor Version 5.00
;
; Adds 'Open in Atom' to context menu (when you right click) in Windows Explorer.
;
; Based on https://github.com/Zren/atom-windows-context-menu. It didn't work
; https://github.com/Zren/atom-windows-context-menu/issues/1.
;
; Save this file to disk with a .reg extension. Replace C:\\Atom\\atom.exe with
; the path to the atom executable on your machine.
@kyle-ilantzis
kyle-ilantzis / RemoveSingleton.hs
Created July 12, 2014 03:29
remove all single occurrences of a character from a string
{-
Given a string and a character, remove from the string all single occurrences
of the character, while retaining all multiple consecutive instances of the
character. For instance, given string “XabXXcdX”, removing singleton Xs
leaves the string “abXXcd”.
http://programmingpraxis.com/2014/06/06/remove-singleton/
-}
{-
{-
http://programmingpraxis.com/2014/06/10/balanced-delimiters-2/
Examples of strings that pass: {}, [], (), a(b)c, abc[d], a(b)c{d[e]}
Examples of strings that don’t pass: {], (], a(b]c, abc[d}, a(b)c{d[e}]
-}
import Control.Monad(foldM,mapM_)
isHead _ [] = False
isHead x xs = x == head xs
@kyle-ilantzis
kyle-ilantzis / saxjserrs.js
Last active January 4, 2016 07:39
isaacs / sax-js error events
var sax = require("sax"),
strict = true, // set to false for html-mode
parser = sax.parser(strict);
parser.onerror = function (e) {
// an error happened.
console.log("error");
console.log(e);
parser.resume();
};