Skip to content

Instantly share code, notes, and snippets.

View g3d's full-sized avatar
🚀
To the moon!

Bohdan V. g3d

🚀
To the moon!
View GitHub Profile
@cesarfigueroa
cesarfigueroa / length.rb
Last active December 14, 2015 23:39
Grape length validator
class Length < Grape::Validations::SingleOptionValidator
def validate_param!(attr_name, params)
case @option
when Integer
unless params[attr_name].to_s.length == @option
throw :error, :status => 400,
:message => "#{attr_name} must be #{@option} characters long"
end
when Range
unless @option.include?(params[attr_name].to_s.length)
@jonkgrimes
jonkgrimes / unicorn.rb
Last active November 18, 2016 18:44
Unicorn.rb for keen.io configuration
worker_processes 3 # amount of unicorn workers to spin up
timeout 30 # restarts workers that hang for 30 seconds
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
before_fork do |server,worker|
defined?(ActiveRecord::Base) and
@subelsky
subelsky / asset.rake
Created March 3, 2013 21:48
Quick rake task to check if assets need to pre-compiled before deployment (since I don't like precompiling during deployment)
namespace :assets do
task :check do
root_dir = File.join(File.dirname(__FILE__),"..","..")
assets_last_modified_at = Dir["#{root_dir}/app/assets/**/**"].map { |p| File.mtime(p) }.sort.last
assets_last_compiled_at = Dir["#{root_dir}/public/assets/**/**"].map { |p| File.mtime(p) }.sort.last
if assets_last_modified_at > assets_last_compiled_at
fail "Assets need to precompiled; last asset modified at #{assets_last_modified_at}"
end
end
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active May 22, 2024 05:53
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@dstroot
dstroot / install-redis.sh
Created May 23, 2012 17:56
Install Redis on Amazon EC2 AMI
#!/bin/bash
# from here: http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/
# and here: https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server
###############################################
# To use:
# wget https://raw.github.com/gist/2776679/04ca3bbb9f085b192f6aca945120fe12d59f15f9/install-redis.sh
# chmod 777 install-redis.sh
# ./install-redis.sh
###############################################
echo "*****************************************"
@mbinna
mbinna / hack.sh
Created April 11, 2012 05:57 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2357277/hack.sh | sh
#
@jamiehodge
jamiehodge / mount.rb
Created April 10, 2012 14:31
sinatra/mount
module Sinatra
module Mount
def mount(app, route="/#{app.name.downcase}")
%w{get post put delete patch options}.each do |method|
self.send method.to_sym, "#{route}*" do
app.call(
env.merge!(
'SCRIPT_NAME' => route.split('/').last,
'PATH_INFO' => params.delete('splat').join('/')
@keikubo
keikubo / README.md
Created March 20, 2012 01:38
Nginx + Unicorn for Rails on Rackhub

Nginx + Unicorn for Rails on Rackhub

Description:

This script enables you to launch your Rails application in production environment (port:80) with Nginx and Unicorn.

Installation:

Please make sure that your Gemfile in your rails application includes unicorn.

@fknappe
fknappe / 1.eloquent_ruby_basics.markdown
Created February 12, 2012 05:24
Eloquent Ruby Highlights

Chapter 1. Basics

Ruby style programming was built on two simple ideas:

  1. Code must be crystal clear
  2. Code must be concise

Example:

@christianchristensen
christianchristensen / gist:1683963
Created January 26, 2012 17:40
nginx + php OSX local

(originally from: http://elytra.net/2011/03/31/hello-world/)

Howto

Install nginx+PHP:

brew install https://raw.github.com/ampt/homebrew/php/Library/Formula/php.rb --with-fpm --with-mysql --enable-cgi
brew install nginx