Skip to content

Instantly share code, notes, and snippets.

View chaimleib's full-sized avatar

Chaim Halbert chaimleib

View GitHub Profile
def shell_escape(s, quote_empty=True):
if quote_empty and s == '':
return "''"
squot = False
dquot = False
dquot_special = False
special = False
escaped = []
for c in s:
if c == "'":
@chaimleib
chaimleib / filterJavaErrors.sed
Created January 6, 2020 22:15
Collapse Java stack traces (sed)
#!/usr/bin/env sed -n -f
### Collapse third-party errors to
### at com.thirdparty.theirPackage first error text
### ...
### at com.thirdparty.theirPackage last error text
{
:loop
/\t*at com\.evernote/ b print
@chaimleib
chaimleib / haikunate.js
Created January 6, 2020 22:14
Haikunator CLI (node)
#!/usr/bin/env node
/*
Requirements:
node v7.6.0
node-getopt
haikunator
*/
const path = require('path');
@chaimleib
chaimleib / lsdiff.js
Created January 6, 2020 22:12
List differences between folders in ls output
#!/usr/bin/env node
/*
Requirements:
node v7.6.0
node-getopt
*/
const path = require('path');
const Promise = require('bluebird');
@chaimleib
chaimleib / json-redirects.sh
Created January 6, 2020 22:09
Convert TSV to JSON redirects using AWK
#!/bin/bash
# Converts .tsv files with cols [ intl?, from, to ] into JSONs.
#
# Usage:
# 1. Go to our list of redirects at https://docs.google.com/spreadsheets/d/1u4hQyNn86R1xzh8G30e14rSbvQs9S6CtsIgmz0NNIKk/edit#gid=549054781
# 2. Download each sheet as a .tsv.
# 3. path/to/json-redirects.sh ~/Downloads/*.tsv > path/to/marketing-dev/redirects.json
#
# In the results jsons, the keys are the "from" addresses, and the values the
# "to" addresses. "To" addresses on the marketing web site are rewritten to be
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>For loop benchmark</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@chaimleib
chaimleib / relativeUrl.html
Created February 2, 2018 20:26
trim hostname from fully-qualified URL
<!doctype html>
<html>
<head>
<title>Test</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
</head>
<body>
<div class="main">
hello
</div>
@chaimleib
chaimleib / reload.html
Created February 2, 2018 20:25
button refreshes the page
<html>
<body>
<h1>Hello</h1>
<button type="button" onClick="location.href = location.href;">Refresh</button>
</html>
@chaimleib
chaimleib / Preferences.sublime-settings
Created December 26, 2017 21:20
Sublime text prefs
{
"color_scheme": "Packages/Color Scheme - Default/Blackboard.tmTheme",
"folder_exclude_patterns":
[
".svn",
".git",
".hg",
"CVS",
"node_modules",
".cache",
# Install homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
brew install ruby
# Install rvm
\curl -sSL https://get.rvm.io | bash -s stable --ruby
rvm install 2.4