Skip to content

Instantly share code, notes, and snippets.

@janlelis
janlelis / .irbrc
Last active November 7, 2016 22:48
irbtools without # => rocket
require 'irbtools/configure'
# require 'irbtools/more'
Irbtools.replace_library_callback :fancy_irb do
FancyIrb.start rocket_mode: false
end
Irbtools.start
require "stringio"
def capture_stdout
capture = StringIO.new
restore, $stdout = $stdout, capture
yield
$stdout = restore
capture.string
end
#!/bin/sh
if [ -n "$(git status --porcelain)" ]; then
echo "\033[31;1mWorking directory needs to be clean\033[0m";
exit 1
else
git checkout production &&
git rebase develop &&
npm run build &&
git add -f dist &&
@janlelis
janlelis / palava
Created December 21, 2013 19:57
An example nginx config to setup the palava-portal and a palava-machine.
upstream palava_machine {
server 127.0.0.1:4240;
}
server {
listen 443 ssl;
server_name example.com; # TODO
ssl on;
ssl_certificate /path/to/your/ssl/cert.crt; # TODO
@janlelis
janlelis / palava-machine
Created December 21, 2013 19:35
A simple init script for the palava-machine. Put it in /etc/init.d/ and make it executable.
#!/bin/bash
invoke()
{
echo "[$1]"
su - palava -c "ruby -S palava-machine-daemon $1"
}
start_multiple()
{
@janlelis
janlelis / ruby_indentation.rb
Created January 12, 2012 22:12
gem install ruby_indentation
require 'coderay'
require 'set'
module RubyIndentation
VERSION = '0.2.0'
def self.[](buffer)
opening_and_modifier_tokens = %w[if unless until while].to_set
opening_tokens = %w[begin case class def for module do {].to_set
closing_tokens = %w[end }].to_set
@janlelis
janlelis / permalink.js
Created December 5, 2011 17:05
pagination vs. permalinks
@janlelis
janlelis / hole4.rb
Created November 22, 2011 04:11
ruby source golf 2011-11-21
# hole 3 in 93 bytes (only counting newlines between method body)
# see http://rubysource.com/ruby-golf/
def play(i)
s=%w[Rock Paper Scissors]
p=s.index i
s[c=rand(3)]+",#{p==c ?:Draw: p&&p==-~c%3?:Win: :Lose}"
end
@janlelis
janlelis / pws.rb
Created November 1, 2010 16:58
Build your own PasswordSafe with Ruby
# pws has been refactored! See https://github.com/janlelis/pws
# christmas tree (golfed version): http://www.ruby-mine.de/2009/11/22/weihnachten
puts"Grösse?"
(Z.times{|n|0.upto(Z){puts" "*(2*Z-n)+"*%d"%(n+=1)*n}
$*<<"%#{2*Z+2}s"%:II}
puts$*)if 0<Z=gets.to_i