Skip to content

Instantly share code, notes, and snippets.

@bitdivine
bitdivine / install-chrome.sh
Last active May 15, 2017 11:49
Install Google Chrome on Ubuntu
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
sudo apt-get update && sudo apt-get install -yy google-chrome-stable
@bitdivine
bitdivine / ansible-profile.sh
Created May 15, 2017 10:38
Source an Ansible profile
# The credentials file looks like this:
# [profile-name]
# VAR_1=something
# VAR_2=else
#
# [another-profile]
# ...
source <(sed -n "/^\[${profile}\]/,/^\[/{/^[^[]/p}" ~/.aws/credentials)
@bitdivine
bitdivine / install-ubuntu.sh
Last active April 27, 2017 19:08
Install google chrome on ubuntu
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list'
sudo apt-get update && sudo apt-get install -yy google-chrome-stable
@bitdivine
bitdivine / aws-fingerprint.sh
Created March 14, 2017 05:20
Get the AWS ssh key fingerprint from a public key
openssl rsa -RSAPublicKey_in -in <(ssh-keygen -f ~/.ssh/id_rsa.pub -e -m PEM) -inform PEM -outform DER 2>/dev/null | openssl md5 -c | awk '{print $2}'
@bitdivine
bitdivine / div-as-input.js
Created November 27, 2016 17:02
Rich text editor as a form input (WYSIWYG contenteditable)
(function(){
// This is a WYSIWYG editing div that can be used as in input in a form.
// Usage: <div contenteditable is="with-input" name="..."></div>
// This can be used in a form and values will be submitted as with a text input.
// You can also get the input with:
// Array.from(document.querySelectorAll('input')).reduce((d,e) => {d[e.name]=e.value;return d;}, {});
// The div is a visual component. An invisible input is appended to
// hold the form data. Any changes made to the div will change the
// value of the input element.
const global = window;
@bitdivine
bitdivine / gist:049f0b48a910e460f38b6c5288e4b2b4
Created November 8, 2016 07:43 — forked from wacko/gist:5577187
SSH between Mac OS X host and Virtual Box guest

On Mac OS (host):

Shutdown your VM and do:

VirtualBox > Settings > Network > Add (you will get vboxnet0)

On a terminal ifconfig will show you new interface vboxnet0

VM's Settings > System > check "Enable I/O APIC." VM's Settings > Network > Adapter 2 > host-only vboxnet0

@bitdivine
bitdivine / random_row.sql
Created August 8, 2016 14:14
Fast select random row from a Postgres table.
select * from MY_TABLE offset random()*(select count(*) from MY_TABLE) limit 1;
@bitdivine
bitdivine / text2html.js
Last active August 4, 2016 18:50
text2html
function text2html(html,wrappertag){var wrapper= document.createElement(wrappertag||'div');wrapper.innerHTML= html;return wrapper;}
function getscript(url){var script = document.createElement('script');script.type = 'text/javascript';script.src = url;document.head.appendChild(script);}
@bitdivine
bitdivine / hashform.js
Created August 4, 2016 17:07
Save html inputs in the location hash.
function get_input_dict(selector){return Array.from(document.querySelectorAll(selector || 'input')).reduce((d,n)=>{d[n.name]=n.value;return d;},{});}
function get_input_hash(selector){return Array.from(document.querySelectorAll(selector || 'input')).map((n)=>encodeURIComponent(n.name)+'='+encodeURIComponent(n.value)).join('&');}
function save_input_hash(selector){window.location.hash = get_input_hash(selector);}
function restore_input_hash(selector){window.location.hash.slice(1).split('&').map((s)=>s.match(/^([^=]*)=(.*)/)).filter((s)=>s).forEach((m)=>Array.from(document.querySelectorAll(`${selector||"input"}[name=${decodeURIComponent(m[1])}]`)).forEach((n) => n.value=decodeURIComponent(m[2])));}
@bitdivine
bitdivine / db_dump_thing.sh
Last active July 28, 2016 18:35
Copy the contents of a table or view into a local database.
#!/usr/bin/env bash
set -eu
help() {
cat <<EOF
Copy the contents of a table or view into a local database.
The copy is always a table, so view dependencies don't have to be downloaded.
SELECT is optionally granted to a named user.
dump --ssh USER@HOST:PORT --from USER@DATABASE:PORT/table --to USER@DATABASE:PORT --grant USER