Skip to content

Instantly share code, notes, and snippets.

View jpbochi's full-sized avatar
🦔

JP Bochi jpbochi

🦔
View GitHub Profile
@jpbochi
jpbochi / underscore_groupby_with_selector.js
Created September 26, 2012 02:34
underscore.js extended groupBy with value selector
// The code below will extend underscore.js adding the groupByAndMap function.
// groupByAndMap works like the regular groupBy, but it accepts an optional third "selector" argument.
// The 'selector' is used to select values inside each group.
// As usual in underscore, you can either pass a function or a string with the name of an attribute you want.
// groupByAndMap is useful when you don't want the key to be present in the values inside the group.
// Also, it completely covers the groupBy functionality because the last argument is optional.
// If you want, you can replace groupBy instead of defining a new function.
_.mixin({
groupByAndMap: function(list, keySelector, valueSelector) {
@jpbochi
jpbochi / robot.js
Created December 6, 2012 00:00 — forked from Shipow/robot.js
Shipow#001 (fork)
var Robot = function(robot) {
robot.rotateCannon(-90);
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead();
//i'll add a clone but i need to refactor collision
//robot.clone();
};
@jpbochi
jpbochi / robot.js
Created December 10, 2012 01:23 — forked from apretto/robot.js
Fluffy Unicorn Mk.I
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
var helperFuncs = {
center: function (robot, helper) {
return {x: robot.arenaWidth/2,
@jpbochi
jpbochi / hats.js
Last active January 2, 2016 06:29
hats
//http://repl.it/IOn
function problem(colors, prisoners) {
function randomHat() {
return Math.floor(Math.random() * colors);
}
function randomHats() {
var hats = [];
for (var i = 0; i<prisoners; i++) {
@jpbochi
jpbochi / iterm-open.sh
Created August 10, 2016 14:35
iterm-open.sh
#!/bin/sh
# copied from https://gist.github.com/sos4nt/5245210
# In iTerm's Preferences > Profiles > Default > Advanced > Semantic History,
# choose "Run command..." and enter "/your/path/to/iterm_open_with \1 \2".
file "$1" | grep -q "text"
if [ $? -ne 0 ]; then
/usr/bin/open $1
else
@jpbochi
jpbochi / best.sh
Last active August 16, 2016 09:47
bash file template
#!/usr/bin/env bash
# Bash3 Boilerplate. Copyright (c) 2014, kvz.io
# http://kvz.io/blog/2013/11/21/bash-best-practices/
# https://github.com/kvz/bash3boilerplate
set -o errexit
set -o pipefail
set -o nounset
# set -o xtrace

Keybase proof

I hereby claim:

  • I am jpbochi on github.
  • I am jpbochi (https://keybase.io/jpbochi) on keybase.
  • I have a public key whose fingerprint is 63F8 99D6 4386 AA0C AF2F FA06 46C0 764A 272F 53FC

To claim this, I am signing this object:

#!/usr/bin/env sh
set -eu
eval $(ssh-agent -s)
KEYS=$(ls -p /var/ssh-keys/ | grep -v -e '/' -e config -e known_hosts -e '.pub$' -e authorized_keys)
echo "$KEYS" | xargs -I % ssh-add /var/ssh-keys/%
mkdir -p /root/.ssh
ssh-keyscan github.com >> /root/.ssh/known_hosts
echo 'host github.com' > /root/.ssh/config
@jpbochi
jpbochi / try-acquire-lock-s3.sh
Created July 25, 2017 12:56
bash script to lock/unlock resources by using an S3 bucket with file versioning
#!/usr/bin/env bash
set -eu
log () {
echo >&2 "[lock] $@"
}
putLock () {
aws s3api put-object --region $REGION --bucket $BUCKET --key $LOCK_KEY --output text --query 'VersionId'
}
@jpbochi
jpbochi / init.lua
Created October 25, 2017 15:35
Hammerspoon config
hs.loadSpoon('ControlEscape'):start() -- Load Hammerspoon bits from https://github.com/jasonrudolph/ControlEscape.spoon
FRemap = require('foundation_remapping') -- https://github.com/hetima/hammerspoon-foundation_remapping
remapper = FRemap.new()
remapper:remap('§', '`')
remapper:register()
remapperDE = FRemap.new({vendorID=0x258a, productID=0x1006})
remapperDE:remap('lcmd', 'lalt')