Skip to content

Instantly share code, notes, and snippets.

@janlelis
janlelis / rack-notags.rb
Created November 14, 2009 14:41
Rack::NoTags
# # # #
# Rack::NoTags removes < and > from all incoming requests
# http://rbjl.net/12-rack-notags
#
# (c) 2009 - 2010 Jan Lelis
# This software is licensed under the MIT license.
# # # #
module Rack
# 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
@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
@janlelis
janlelis / blip
Created January 16, 2011 14:38
Easy access to your clipboard
#!/usr/bin/env ruby
require 'rubygems' unless defined? Gem
require 'clipboard'
if $stdin.tty? && $*.empty?
puts Clipboard.paste # the trailing new-line is intended ;)
else
Clipboard.copy ARGF.read
end
@janlelis
janlelis / .railsrc
Created March 31, 2011 16:52
13 Rails-specific hints for your rails 3 console.
# .railsrc for Rails 3, encoding: utf-8
# see http://rbjl.net/49-railsrc-rails-console-snippets
if !Rails.application then warn "Rails isn't loaded, yet... skipping .railsrc" else
# # #
def ripl?; defined?(Ripl) && Ripl.instance_variable_get(:@shell); end
# # #
# loggers
# Colorizes the output of the standard library logger, depending on the logger level:
# To adjust the colors, look at Logger::Colors::SCHEMA and Logger::Colors::constants
require 'logger'
class Logger
module Colors
VERSION = '1.0.0'
NOTHING = '0;0'
@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 / permalink.js
Created December 5, 2011 17:05
pagination vs. permalinks
@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 / gemfile
Created August 19, 2012 12:29
Displays gem urls and summaries found in a Gemfile
#!/usr/bin/env ruby
# USAGE
# gemfile [--bundle] [--details] [--fetch] [--sorted] [--commentate]
# DESCRIPTION
# Displays gem urls and summaries found in a Gemfile.
# cd into a directory with a Gemfile and run `gemfile`
# PREREQUISITES
# gem install bundler paint
# FLAGS