Skip to content

Instantly share code, notes, and snippets.

@re5et
re5et / dig.rb
Created March 2, 2012 01:29
ruby hash dig
class Hash
def dig(*path)
path.inject(self) do |location, key|
location.is_a?(Hash) ? location[key] : nil
end
end
end
@re5et
re5et / no-final.js
Created February 22, 2016 04:00
huh
const crypto = require('crypto');
const algorithm = 'aes-256-ctr';
const password = 'DERRRRP'
function encrypt(text){
const cipher = crypto.createCipher(algorithm, password)
const crypted = cipher.update(text,'utf8','hex')
return crypted;
}
(defun async-command-and-highlight (command highlights &optional output-buffer)
(kill-buffer output-buffer)
(async-shell-command command output-buffer)
(with-current-buffer output-buffer
(mapcar
(lambda (highlight)
(highlight-phrase (car highlight) (cdr highlight)))
highlights)))
(async-command-and-highlight
class ActiveRecord::Base
def self.boolean_returning_transaction
begin
result = false
result = ActiveRecord::Base.transaction do
yield
return true
end
rescue
@re5et
re5et / force-save.el
Created August 27, 2013 21:59
Save a buffer, even if it hasn't been modified. I use this to touch / save a buffer when I want a test to run, etc.
(global-set-key (kbd "C-x C-s") 'force-save)
(defun force-save ()
(interactive)
(not-modified 1)
(save-buffer))
# RSpec matcher for validates_with.
# https://gist.github.com/2032846
# Usage:
#
# describe User do
# it { should validate_with CustomValidator }
# end
RSpec::Matchers.define :validate_with do |validator, options = {}|
match do |subject|
@re5et
re5et / node_https.js
Created July 1, 2013 19:34
node https server
const crypto = require('crypto'),
fs = require("fs"),
http = require("http");
var privateKey = fs.readFileSync('privatekey.pem').toString();
var certificate = fs.readFileSync('certificate.pem').toString();
var credentials = crypto.createCredentials({key: privateKey, cert: certificate});
var handler = function (req, res) {
#! /bin/bash
case "$1" in
'' | -h | --help)
NOARGS=1 ;;
-d)
DRY=1; FIND=$2 ;;
*)
DRY=0; FIND=$1 ;;
esac
@re5et
re5et / git_repo_sync.sh
Created March 7, 2013 01:26
git repo sync
#! /usr/bin/env bash
checkout_dir=$1
from_remote=$2
to_remote=$3
cd $checkout_dir
(defun prettify-json ()
"NOTE: requires ruby in $PATH. Replace a valid json region with
pretty printed json By default uses the jj method to print,
uses pp if there is a prefix argument"
(interactive)
(let* ((print-method (if current-prefix-arg "pp" "jj"))
(cmd (format
"ruby -e 'require \"json\"; require \"pp\"; %s JSON.parse(gets)'" print-method)))
(shell-command-on-region
(region-beginning)