This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hash | |
def dig(*path) | |
path.inject(self) do |location, key| | |
location.is_a?(Hash) ? location[key] : nil | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActiveRecord::Base | |
def self.boolean_returning_transaction | |
begin | |
result = false | |
result = ActiveRecord::Base.transaction do | |
yield | |
return true | |
end | |
rescue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(global-set-key (kbd "C-x C-s") 'force-save) | |
(defun force-save () | |
(interactive) | |
(not-modified 1) | |
(save-buffer)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
case "$1" in | |
'' | -h | --help) | |
NOARGS=1 ;; | |
-d) | |
DRY=1; FIND=$2 ;; | |
*) | |
DRY=0; FIND=$1 ;; | |
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
checkout_dir=$1 | |
from_remote=$2 | |
to_remote=$3 | |
cd $checkout_dir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
NewerOlder