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
@jnstq
jnstq / installer_controller.rb
Created March 23, 2023 20:09 — forked from adamloving/installer_controller.rb
Rails controller action for an HTML5 cache manifest file.
class InstallerController < ApplicationController
# Rails controller action for an HTML5 cache manifest file.
# Generates a plain text list of files that changes
# when one of the listed files change...
# So the client knows when to refresh its cache.
def cache_manifest
@files = ["CACHE MANIFEST\n"]
@files << 'favicon.ico'
module DeepCompact
def self.blank?(o)
o.nil? || (o.respond_to?(:empty?) && o.empty?)
end
module Array
def deep_compact
map.with_object(self.class.new) { |e, o|
o << (e.respond_to?(:deep_compact) ? e.deep_compact : e)
}.select { |value| !DeepCompact.blank?(value) }
@jnstq
jnstq / README.txt
Created February 22, 2012 12:54 — forked from rmm5t/README.md
Locale override examples for the timeago jQuery plugin (http://timeago.yarp.com)
You can represent time statements in most western languages where
a prefix and/or suffix is used.
The default case is to use suffix only (as in English), which you
do by providing the `suffixAgo` and `suffixFromNow` settings in
the strings hash (earlier versions of timeago used the deprecated
`ago` and `fromNow` options). If present, they are used.
2 minutes [suffixAgo]
2 minutes [suffixFromNow]
#Taken from http://coderrr.wordpress.com/2008/04/22/building-the-right-class-with-sti-in-rails/
class GenericClass < ActiveRecord::Base
class << self
def new_with_cast(*a, &b)
if (h = a.first).is_a? Hash and (type = h[:type] || h['type']) and (klass = type.constantize) != self
raise "wtF hax!!" unless klass < self # klass should be a descendant of us
return klass.new(*a, &b)
end
@jnstq
jnstq / bitly.rb
Created May 3, 2011 20:06 — forked from jehiah/bitly.rb
# Bit.ly API implementation - thanks to Richard Johansso http://gist.github.com/112191
require 'httparty'
class Api::Bitly
include HTTParty
base_uri 'api.bit.ly'
format :json
# Usage: Bitly.shorten("http://example.com")
def self.shorten(url)
Surround these with : e.g. :calling:
+1
-1
bulb
calling
clap
cop
email
feet
after "deploy:stop", "delayed_job:stop"
after "deploy:start", "delayed_job:start"
after "deploy:restart", "delayed_job:restart"
namespace :delayed_job do
desc "Stop the delayed_job process"
task :stop, :roles => :app do
run "cd #{current_path}; script/delayed_job -e #{rails_env} stop"
end
#!/opt/ruby/bin/ruby
# put in /etc/munin/plugins and restart munin-node
# by Dan Manges, http://www.dcmanges.com/blog/rails-application-visualization-with-munin
# NOTE: you might need to add munin to allow passwordless sudo for passenger-memory-stats
def output_config
puts <<-END
graph_category App
graph_title Passenger memory stats
graph_vlabel count
#!/opt/ruby/bin/ruby
def output_config
puts <<-END
graph_category App
graph_title passenger status
graph_vlabel count
sessions.label sessions
max.label max processes
/* Ismael Celis 2010
Simplified WebSocket events dispatcher (no channels, no users)
var socket = new ServerEventsDispatcher();
// bind to server events
socket.bind('some_event', function(data){
alert(data.name + ' says: ' + data.message)
});