A collection of handy one-liners and snippets by Paul Engel
bash -c 'source /path/to/your/.env; echo $MYENVVAR'
=block | |
display: block | |
=clear | |
*display: inline-block | |
&:after | |
content: " " | |
height: 0 | |
+block | |
clear: both |
function current_rvm_ruby { | |
color=$(tput setaf 3) | |
default=$(tput sgr0) | |
version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') | |
gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') | |
[ "$gemset" != "" ] && gemset="@$gemset" | |
full=${color}${version}${gemset}${default} | |
[ "$full" != "" ] && echo "$full " | |
} |
function inspect(object) { | |
switch (typeof(object)) { | |
case "undefined": | |
return "undefined"; | |
case "string": | |
return "\"" + object.replace(/\n/g, "\\n").replace(/\"/g, "\\\"") + "\""; | |
case "object": | |
if (object == null) { | |
return "null"; | |
} |
def pretty_inspect(object, indent = 2) | |
if object.is_a?(Array) | |
entries = object.collect{|x| "#{pretty_inspect x, indent + 2}"} | |
pretty_indent entries, "[", "]", indent | |
elsif object.is_a?(Hash) | |
entries = object.keys.sort.collect{|x| "#{pretty_inspect x} => #{pretty_inspect object[x], indent + 2}"} | |
pretty_indent entries, "{", "}", indent | |
else | |
object.inspect | |
end |
require_relative "task" | |
desc "Send an invite" | |
task :invite do |name, email| | |
puts "Invitation sent to '#{name} <#{email}>'" | |
end | |
# Example: | |
# | |
# $ rake invite "Paul Engel" [email protected] |
A collection of handy one-liners and snippets by Paul Engel
bash -c 'source /path/to/your/.env; echo $MYENVVAR'
var mod, define; | |
mod = (function() { | |
'use strict'; | |
var modules = {}; | |
return { | |
define: function(name, mod) { | |
modules[name] = (typeof(mod) == 'function') ? mod : function() { return mod; }; |
# iex(1)> | |
ast = quote do: 1 + 1 | |
# iex(2)> | |
Code.eval_quoted(ast) | |
# iex(3)> | |
ast = quote do: sum(1, 2 + 3) | |
# iex(4)> |
require "net/telnet" | |
def keys(hosts, pattern = nil) | |
[hosts].flatten.each do |host| | |
slabs = {} | |
telnet = Net::Telnet::new("Host" => host, "Port" => 11211, "Timeout" => 3) | |
telnet.cmd("String" => "stats items", "Match" => /^END/) do |stats| | |
slabs = Hash[stats.scan(/STAT items:(\d+):number (\d+)/)] | |
end |