Skip to content

Instantly share code, notes, and snippets.

View longlostnick's full-sized avatar

Nick Larson longlostnick

View GitHub Profile
@longlostnick
longlostnick / migrate_redis.rb
Created June 27, 2016 23:51
Migrate redis key/values by key match
require 'redis'
redisSrc = Redis.connect url: "redis://<src>:6379"
redisDest = Redis.connect url: "redis://<dest>:6379"
redisSrc.keys("*").each do |key|
begin
data = redisSrc.dump key
ttl = redisSrc.pttl key # milleseconds
redisDest.restore key, ttl, data
@longlostnick
longlostnick / values_pointers.go
Created April 5, 2016 06:50 — forked from josephspurrier/values_pointers.go
Golang - Asterisk and Ampersand Cheatsheet
/*
********************************************************************************
Golang - Asterisk and Ampersand Cheatsheet
********************************************************************************
Also available at: https://play.golang.org/p/lNpnS9j1ma
Allowed:
--------
p := Person{"Hillary", 28} stores the value
@longlostnick
longlostnick / .bashrc
Created March 19, 2016 04:19 — forked from vsouza/.bashrc
Golang 1.5 setup in Mac OSX with HomeBrew. Set `GOPATH` and `GOROOT` variables in zshell or bash.
# Set variables in .bashrc file
# don't forget to change your path correctly!
export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
@longlostnick
longlostnick / 01_postfix_installer.md
Created February 14, 2016 08:14 — forked from solusipse/01_postfix_installer.md
Postfix + Dovecot + Postgresql + Postfixadmin + Roundcube

Postfix Installer

Following script may be used for configuring complete and secure email server on fresh install of Debian 7. It will probably work on other distributions using apt-get. After minor changes you'll be able to use it on other Linux distros.

Usage

  1. Run postfix.sh script.
  2. Configure postgres to allow connections.
  3. Configure postfix admin. Remember to set these:
@longlostnick
longlostnick / README.md
Last active August 23, 2021 07:52
Read, transform, and write a csv file
@longlostnick
longlostnick / install_vbox_guest_additions.md
Last active December 11, 2015 18:38
Install VirtualBox Guest Additions (Linux)

Devices > Install Guest Additions CD Image

mount /dev/sr0 /media/cdrom && cd /media/cdrom
./VBoxLinuxAdditions.run
@longlostnick
longlostnick / accept_nested_attributes.js
Last active November 3, 2015 21:53
FormBuilder addition for models that accept nested attributes.
function addNestedRow(e) {
e.preventDefault();
// http://railscasts.com/episodes/197-nested-model-form-part-2
var html = $('#my-attribute-link-template').html();
var $attr_row = $(html.replace(/new_MyAttribute/g, new Date().getTime()));
$('#my-attributes').append($attr_row);
};
@longlostnick
longlostnick / random_password.rb
Created September 8, 2015 17:22
Safari like random passwords in ruby
BASE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
def random_string(length = 3)
length.times.map { BASE[rand(BASE.length)] }.join
end
puts 4.times.map { random_string }.join('-')
@longlostnick
longlostnick / hash_dig.rb
Created July 14, 2015 20:36
"Dig" through hash using dot notation
class Hash
def dig(dotted_path)
parts = dotted_path.split '.', 2
first_part = parts[0]
match = self[first_part] || self[first_part.to_sym]
if !parts[1] || match.nil?
return match
else
return match.dig(parts[1])
end
@longlostnick
longlostnick / hashquiz.rb
Last active August 29, 2015 14:24 — forked from potatosalad/hashquiz.rb
Ruby quiz for convert hash "dot paths" into actual hash hierarchy.
#require 'rubygems'
require 'pp'
#require 'ap' # Awesome Print
class Object
# expects [ [ symbol, *args ], ... ]
def recursive_send(*args)
args.inject(self) { |obj, m| obj.send(m.shift, *m) }
end
end