Skip to content

Instantly share code, notes, and snippets.

View jnstq's full-sized avatar

Jon Stenqvist jnstq

  • Equipe AB
  • Helsingborg, Sweden
View GitHub Profile
@rmm5t
rmm5t / README.md
Created August 19, 2008 23:38
Locale override examples for the timeago jQuery plugin (http://timeago.yarp.com)

This gist is now deprecated

Please visit the locales directory inside the main timeago repository intead.

# ...
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
if forked
Rails.cache.instance_variable_get(:@data).reset if Rails.cache.class == ActiveSupport::Cache::MemCacheStore
ActionController::Base.session_options[:cache].reset
end
end
end
# as we’re going to use Unicorn as the application server
# we’re not going to use common sockets
# but Unix sockets for faster communication
upstream shop {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a
# single worker for timing out).
# for UNIX domain socket setups:
server unix:/tmp/shop.socket fail_timeout=0;
@kch
kch / rb-magic-comment
Created September 27, 2010 20:25
Add the encoding magic comment to the ruby files passed as arguments
#!/usr/bin/env ruby
# encoding: UTF-8
ARGV.reject! { |path| !File.file?(path) }
(puts DATA.read.gsub("$0", File.basename($0)); exit 1) if ARGV.empty?
ARGV.each do |path|
ls = IO.readlines(path)
ix = ls[0] !~ /^#!/ ? 0 : 1
next if ls[ix] =~ /#.*?coding\s*[:=]\s*\S/
@slippycheeze
slippycheeze / obfuscate.rb
Created April 16, 2011 03:42
Obfuscated Ruby for producing Obfusctated Ruby.
c = "\n !\"#'()*+,./01234678;<=ABCDEGINOPRSTUVY[\\]_abcdefghijlmnopqrstuvxy{|}".split('')
i = <<'EOT' .gsub(/\n/, '').to_i(36)
cuwnbkpknpgvndxhiywcb8v7r6px9dgwojmf4inpx5a0irzlmxiaisomq7ir6zx1yhrkk42gltj7vy
nibeul3djwhv9hy0jcjptfh9vvwmnw3xyn4k32gjflrdbb3f1t1xt3w690js9ri5idnch6f9y1ym6r
a2e9okgnsrofg1ztnq9zdbtfh7qmhy22psuo3cdxv1aaq3bf7q0bv12nj8ld7tshysxekfz8jwmff7
k0okucxt2abkmapldjqb6m2vzo43r3g4j9zscr8svoi3ktv63jddl5dokfgl1rmi9sygylc8jor243
ywnovju7t8kvuf2bpy33zkp6w7k97lok9ymo8shfs9m83rq85snkiex96hjykqkf8noaeap18b2rvo
4vrmdy6a7pm28m5b7ye9e58i0xp89ckgx9xuth43ngwfgmoomp2v5dau2ep3hovpthhmklo47j7ds4
714qvy44hmzk24v95gycadjnqkvrbqqip3k7ap901q0eiuvouweg9mlsm4r6y78rpamf8rlqzltyw8
3uf9qqs9sz0au0hyjicqiu3m5xb40yydj6qfigauo1wlmdctonk3a3e9s5vyhrxqmmck89fsupxprp
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@coreyhaines
coreyhaines / my stats
Created December 8, 2011 21:08
Sample of my old custom stats file that adds spec_no_rails
if ENV['LOAD_RAILS'] == '1'
task :stats => "ma:add_no_rails_dirs_to_stats"
namespace :ma do
desc "Report code statistics (KLOCs, etc) from the application"
task :add_no_rails_dirs_to_stats do
require 'rails/code_statistics'
::STATS_DIRECTORIES << %w(NoRails\ Lib\ specs spec_no_rails/lib) if File.exist?('spec_no_rails/lib')
::CodeStatistics::TEST_TYPES << "NoRails Lib specs" if File.exist?('spec_no_rails/lib')
::STATS_DIRECTORIES << %w(NoRails\ Model\ specs spec_no_rails/model) if File.exist?('spec_no_rails/model')
@josevalim
josevalim / 1_README.md
Created December 13, 2011 09:30
FSSM based FileWatcher for Rails

Rails 3.2 ships with a simple FileWatcher that only reloads your app if any of the files changed.

Besides, it also provides a mechanism to hook up your own file watcher mechanism, so we can use tools like FSSM that hooks into Mac OS X fsevents. This is an example on how to hook your own mechanism (you need Rails master, soon to be Rails 3.2):

  1. Copy the 2_file_watcher.rb file below to lib/file_watcher.rb

  2. Add the following inside your Application in config/application.rb

if Rails.env.development?

@ryanb
ryanb / index.js.erb
Created December 16, 2011 23:22
Infinite scrolling solution covered in revised episode #114: http://railscasts.com/episodes/114-endless-page-revised
$('#products').append('<%= j render(@products) %>');
<% if @products.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@products) %>');
<% else %>
$('.pagination').remove();
<% end %>
@cbmeeks
cbmeeks / bootstrap_form_builder.rb
Created December 28, 2011 03:59
Twitter Bootstrap Form Builder
class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
delegate :capture, :content_tag, :tag, to: :@template
%w[text_field text_area password_field collection_select].each do |method_name|
define_method(method_name) do |name, *args|
errors = object.errors[name].any?? " error" : ""
error_msg = object.errors[name].any?? content_tag(:span, object.errors[name].join(","), class: "help-inline") : ""
content_tag :div, class: "clearfix#{errors}" do