Skip to content

Instantly share code, notes, and snippets.

View bemurphy's full-sized avatar

Brendon Murphy bemurphy

View GitHub Profile
def daemonize(name = File.basename($0), options = {})
pid_path = options[:pid_path] || File.expand_path("tmp/pids/#{name}.pid")
# If the pid file exists, check that the process is actually still running.
begin
if File.exists?(pid_path) && Process.kill(0, File.read(pid_path).to_i)
$stderr.puts "Already running."
exit 1
end
rescue Errno::ESRCH
@xaviershay
xaviershay / build_frontend.sh
Last active December 24, 2015 20:49
SASS + Coffee + Concatenation in prod
#!/bin/bash
set -exo pipefail
BUILD_ENV=$1
if [ `uname` == 'Darwin' ]; then
OSX=1
JSCOMPRESSOR="yuicompressor --type js"
else
OSX=
#!/usr/bin/env ruby --disable-gems
# Roll your own two-factor authentication! Place this file on a USB key, make
# it executable, then run:
#
# two-factor --setup
#
# Now place each TOTP secret in its own file in the `keys/` directory. I like
# to name them after the website they apply to, but any name is fine. To
# generate a token, plug in your USB key and:
@pedrosmmoreira
pedrosmmoreira / final_controller_calls.rb
Last active January 21, 2016 06:40
Dynamic Pundit Policies per user type
class FoosController < ApplicationController
include Pundit
#...
# record policy
def set_record_policy
policy(PolicyContext.new(record, current_user)
end
# scope policy
@joost
joost / change_s3_metadata.rb
Last active August 26, 2016 01:40
Change metadata on existing S3 files
# Using v1 of Ruby aws-sdk as currently v2 seems not able to do this (broken?).
require 'aws-sdk-v1'
key = YOUR_AWS_KEY
secret = YOUR_AWS_SECRET
region = YOUR_AWS_REGION
AWS.config(access_key_id: key, secret_access_key: secret, region: region)
s3 = AWS::S3.new
bucket = s3.buckets[bucket_name]
@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
@ryanfelton
ryanfelton / install_qt5.sh
Last active May 25, 2017 04:01
CircleCI Install Qt5
#!/bin/sh
# Based on: https://gist.github.com/ryanong/ad6e7570e3f72b22c0e4
set -x
# Exit if any subcommand fails
set -e
if [ ! -d "/opt/qt55" ]; then
echo "Installing QT 5.5 ..."
@korny
korny / jquery_ujs.prompt.js.coffee
Last active July 3, 2017 19:06
Simple prompt functionality for Rails / jQuery UJS, modelled after "confirm". Tested with Rails 4 (edge).
# Usage: link_to …, prompt: { message: 'Some message', default: 'default value', param: 'name of parameter' }
# The prompt will ask for "message" and use "default" as the default value.
# Unless user selects cancel, "param"=<new value> will be sent to the given path.
# Optionally, you can just use `prompt: "message"`.
$.rails.prompt = (message, defaultValue) ->
window.prompt message, defaultValue
$.rails.handlePrompt = (element) ->
config = element.data 'prompt'
@jwood
jwood / application.html.erb
Last active March 15, 2021 16:03
Disable animations
<!-- app/views/layouts/application.html.erb -->
<!DOCTYPE html>
<html lang="en">
<head>
<!-- ... -->
<% if Rails.application.config.disable_animations %>
<%= stylesheet_link_tag('disable_animations') %>
<!-- Turn off animations in jQuery -->
<script>$.fx.off = true;</script>
@relaxdiego
relaxdiego / graphite.md
Last active January 5, 2022 09:07 — forked from surjikal/graphite.md
Installing Graphite in OS X Mavericks

Follow these steps to install graphite on OS X Mavericks.

Prerequisites

  • Homebrew
  • Python 2.7
  • Git

Install dependencies

Install Cairo and friends