Skip to content

Instantly share code, notes, and snippets.

@chriskottom
chriskottom / ruby_install.sh
Created October 7, 2010 16:54
Bash script to install Ruby with RVM and selected dependencies on my system
#!/bin/bash
#
# ruby_install.sh
# A simple Bash script for building up my Ruby development environment on a clean system.
# The configuration used is the one that I like.
# - Base system Ruby = version 1.9.2
# - Ruby installed from source
# - Installation of RVM + Rubies
# - Configuration of gemset for local instance of Passenger
@danielpietzsch
danielpietzsch / deploy.rb
Created March 10, 2011 22:50
Deploy a specific or the current Git branch by default using Capistrano
# parses out the current branch you're on. See: http://www.harukizaemon.com/2008/05/deploying-branches-with-capistrano.html
current_branch = `git branch`.match(/\* (\S+)\s/m)[1]
# use the branch specified as a param, then use the current branch. If all fails use master branch
set :branch, ENV['branch'] || current_branch || "master" # you can use the 'branch' parameter on deployment to specify the branch you wish to deploy
@nazarhussain
nazarhussain / Readme
Created June 22, 2011 13:29
Enable conditional default_url for Paperclip, to set default url with some method in the model
In some cases you need to set the default_url of paper clip base on some condition. e.g. You want to set default image on basis of gender of user. For this purpose this gist can make it possible to use a method as default_url. Just copy paper_clip_default_url_fix.rb to initializers folder, and use default_url as mentioned in model.rb
@rkh
rkh / chat.rb
Created December 14, 2011 12:55
Simple Chat Application using the Sinatra Streaming API
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
@willurd
willurd / web-servers.md
Last active May 23, 2024 20:20
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@maccman
maccman / counter.sql
Created July 7, 2013 03:11
Postgres counter cache using triggers.
--
-- Name: c_posts_voted(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION c_posts_voted() RETURNS trigger
LANGUAGE plpgsql
AS $$ BEGIN
UPDATE "posts" SET voted_user_ids = array_append(voted_user_ids, NEW.user_id) WHERE "id" = NEW.post_id;
RETURN NEW;
END;
@rxaviers
rxaviers / gist:7360908
Last active May 23, 2024 23:28
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@rbmrclo
rbmrclo / routes.rb
Last active March 29, 2018 14:34
Rails Best Practices: Routing Concerns in Rails 4
# Routing Concerns is an attempt to DRY up your config/routes.rb.
# The basic idea is to define common sub-resources (like comments)
# as concerns and include them in other resources/routes.
# Here’s the obvious example:
concern :commentable do
resources :comments
end
concern :remarkable do
@joost
joost / deploy.rb
Last active October 10, 2018 09:12 — forked from toobulkeh/deploy.rb
Capistrano 3 rails console tasks
# encoding: UTF-8
# Place in config/deploy.rb
# See: https://gist.github.com/joost/9343156
# Adapted to work with rbenv
namespace :rails do
desc "Open the rails console on primary app server"
task :console do
on roles(:app), primary: true do
rails_env = fetch(:stage)
execute_interactively "#{bundle_cmd} #{current_path}/script/rails console #{rails_env}"
@erlingur
erlingur / upload.rake
Created May 30, 2014 16:37
Capistrano upload task
namespace :deploy do
task :upload do
files = (ENV["FILES"] || "").split(",").map { |f| Dir[f.strip] }.flatten
abort "Please specify at least one file or directory to update (via the FILES environment variable)" if files.empty?
on release_roles :all do
files.each { |file| upload!(file, File.join(current_path, file)) }
end
end
end