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) {
@rodolfo42
rodolfo42 / Db.scala
Last active January 17, 2018 15:23
How to use transactions with finagle-mysql
package transactions
import com.twitter.finagle.exp.mysql.{Client, OK, Result}
class Db(mysqlClient: Client) {
val insertOrder = "INSERT INTO orders (ref) VALUES(?)"
val insertOrderItem = "INSERT INTO order_items (order_id, item_id) VALUES(?, ?)"
def persistOrderWithItems[T](order: Order)(whenDone: (OK, Seq[Result]) => T): Future[T] = {
@sky-y
sky-y / iconv-nfd-to-nfc.sh
Created December 22, 2012 06:07
iconv(Shell Script): Macで濁点が分離する問題を直す (Unicode NFD to NFC)
#!/bin/sh
# Unicode NFD to NFC
# 標準出力に出力されるので、適当にパイプで処理する
iconv -f UTF-8-MAC -t UTF-8 input.txt
@stavxyz
stavxyz / sjs.md
Last active November 6, 2018 17:01
Shit Janus Says

mozair

this hopefully won't break all the things we've ever built

integration tests passed
I don't know if I should be happy or sad

On the release of AWS Edge Location in Vienna

schnitzel shops rejoice

@sos4nt
sos4nt / iterm_open_with
Created March 26, 2013 13:06
Semantic history command for iTerm2 and Sublime Text 3. In iTerm's Preferences > Profiles > Default > Advanced > Semantic History, choose "Run command..." and enter "/your/path/to/iterm_open_with \1 \2".
#!/bin/sh
file "$1" | grep -q "text"
if [ $? -ne 0 ]; then
/usr/bin/open $1
else
/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl $1:$2
fi
@jpbochi
jpbochi / .bash_ps1
Created August 6, 2019 10:33
bash PROMPT_COMMAND + PS1 for git status
#!/usr/bin/env bash
# copied from http://mediadoneright.com/content/ultimate-git-ps1-bash-prompt
# Customize BASH PS1 prompt to show current GIT repository and branch.
# by Mike Stewart - http://MediaDoneRight.com
# TODO: scope the following env vars to this file only. They can be seen with `declare -p`
# Reset
Color_Off="\[\033[0m\]" # Text Reset
@epelc
epelc / cleanup-images.md
Last active October 17, 2019 15:14
Delete Gitlab Registry Images

Soft-delete the images

Generate a script to delete all images using the following. Copy paste into chrome console on the registry page of a project.

NOTE you must update the textToSave template string before running.

// Options(fill these out with your info)

// GITLAB_INSTANCE is the url to your custom instance or `gitlab.com`
const GITLAB_INSTANCE = 'gitlab.yourwebsite.com'
const GROUP = 'yourGroup'

plausible general principles governing valid agreements:

  1. Valid consent requires a reasonable way of opting out.
  2. Explicit dissent has precedence over alleged implicit consent.
  3. An action can be taken as indicating agreement to some scheme only if one can be assumed to believe that if one did not take that action the scheme would not be imposed on the person.
  4. Contractual obligation is mutual and conditional.

How does the relation between individuals and the state holds up against those principles?

  1. No state has provided meaningful ways of opting out, means that do not require dissenters to assume large costs that the state has no independent right to impose.
  2. All modern states in refusing to recognize explicit dissent render their relationships with the citizens non-voluntary.
@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'
}
#!/usr/bin/env zsh
branch=`git rev-parse --abbrev-ref HEAD`
git show-branch | ack '\*' | ack -v "$branch" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//'
# How it works:
# 1| Display a textual history of all commits.
# 2| Ancestors of the current commit are indicated
# by a star. Filter out everything else.