Skip to content

Instantly share code, notes, and snippets.

View baxang's full-sized avatar

Sanghyun Park baxang

  • Jora
  • Sydney, Australia
View GitHub Profile
@jimeh
jimeh / delayed_job.rb
Created March 26, 2010 22:42
delayed_job.rb: Capistrano tasks to "properly" start/stop/restart the delayed_job daemon.
#
# NOTICE: The stop/restart tasks won't work properly due to a bug in the daemons gem
# unless you use the ghazel-daemons gem by putting this in your environment.rb file:
#
# config.gem "ghazel-daemons", :lib => "daemons"
# gem "ghazel-daemons"
# require "daemons"
#
# This will force-load the 'ghazel-daemons' gem and make sure it's used instead of
# the 'daemons' gem. It works even with the 'daemons' gem installed, so you won't
@charly
charly / uploader_fu.rb
Created March 8, 2011 15:39
a nice little module to help migrate from attachment_fu to carrierwave
# Helps you migrate from attachment_fu
# put it in your /lib dir and include it your xxxx_uploader.rb
module UploaderFu
def partition_dir
("%08d" % model.id).scan(/\d{4}/).join("/")
end
def model_dir
"#{model.class.to_s.underscore}/#{mounted_as}/"
@buritica
buritica / iosd
Created March 29, 2012 18:52
Enable Remote Inspector on Mobile Safari
#!/bin/bash
# Open iPhone Simulator on default location for XCode 4.3 if found
[[ -d /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/ ]] &&
open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app
# Open iPhone Simulator on default location for XCode 4.2 if found
[[ -d /Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/ ]] &&
open /Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app
@Vheissu
Vheissu / functions.php
Created October 22, 2012 02:36
Bundling the Advanced Custom Fields plugin into a theme using the TGM Plugin Class
add_action( 'tgmpa_register', 'register_required_plugins' );
// This function is called from the above hook
function register_required_plugins()
{
// The plugins array allows us to define multiple plugins we want to include.
// The commented out example shows how we can include and activation a bundled
// plugin zip file in our theme.
$plugins = array(
/* array(
@Simbul
Simbul / pre-commit
Created February 9, 2012 18:06
Git hook to prevent commits on a staging/production branch
#!/usr/bin/env ruby
# This pre-commit hook will prevent any commit to forbidden branches
# (by default, "staging" and "production").
# Put this file in your local repo, in the .git/hooks folder
# and make sure it is executable.
# The name of the file *must* be "pre-commit" for Git to pick it up.
FORBIDDEN_BRANCHES = ["staging", "production"]
@bf4
bf4 / ability.rb
Last active October 14, 2017 15:15
Cancan, rolify, and active admin
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user (not logged in)
if user.has_role? :admin # rolify
can :manage, :all
can :access, :ckeditor
# Performed checks for actions:
can [:read, :create, :destroy], Ckeditor::Picture
@sj26
sj26 / uploader_input.rb
Created March 13, 2012 02:50
Formtastic input for carrierwave uploaders
# A formtastic input which incorporates carrierwave uploader functionality.
#
# Intelligently adds the cache field, displays and links to the current
# value if there is one, adds a class to the wrapper when replacing an
# existing value, allows removing an existing value with the checkbox
# taking into account validation requirements.
#
# There are several options:
#
# * Toggle the replacement field with `replaceable: true/false`.
@atd-schubert
atd-schubert / starter.sh
Created April 9, 2013 12:53
Solution for starting ArgoUML in Mac OSX Mountain Lion
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "Starting with Mountain Lion start helper"
$DIR/JavaApplicationStub &
@webmat
webmat / dashboards.rb
Created February 22, 2012 20:46
First draft of an active_admin-based view for Delayed::Job
ActiveAdmin::Dashboards.build do
# Add this section in your dashboard...
section "Background Jobs" do
now = Time.now.getgm
ul do
li do
jobs = Delayed::Job.where('failed_at is not null').count(:id)
link_to "#{jobs} failing jobs", admin_jobs_path(q: {failed_at_is_not_null: true}), style: 'color: red'
end
@developer88
developer88 / some_active_admin_resource.rb
Created March 5, 2013 13:49
Add custom method to export table as CSV file for ActiveAdmin Resource + scope items from filter + save csv file compatible with Russian Microsoft Office Excel
filter :reception_reception_date, as: :date_range, label: Reception.human_attribute_name(:reception_date_full)
collection_action :download_report, :method => :get do
services = Service.includes(:order, reception: [{medic: :clinic_medics}]).where{ orders.orderable_id != nil } # necessary model
if params[:q] && params[:q][:reception_reception_date_gte].length > 1
services = services.where("receptions.reception_date >= ?", params[:q][:reception_reception_date_gte])
end
if params[:q] && params[:q][:reception_reception_date_lte].length > 1
services = services.where("receptions.reception_date < ?", params[:q][:reception_reception_date_lte])
end