Skip to content

Instantly share code, notes, and snippets.

@raecoo
raecoo / databases.rake
Created October 13, 2013 01:28
monkey patch ActiveRecord to avoid There are n other session(s) using the database. reference from http://stackoverflow.com/questions/17615574/cucumber-and-rspec-testing-with-zeus-postgres-is-being-accessed-by-other-users/17746382#17746382
#{Rails.root}/lib/tasks/databases.rake
# monkey patch ActiveRecord to avoid There are n other session(s) using the database.
def drop_database(config)
case config['adapter']
when /mysql/
ActiveRecord::Base.establish_connection(config)
ActiveRecord::Base.connection.drop_database config['database']
when /sqlite/
require 'pathname'
path = Pathname.new(config['database'])
class CreateImports < ActiveRecord::Migration
def self.up
create_table :imports do |t|
t.string :datatype
t.integer :processed, :default => 0
t.string :csv_file_name
t.string :csv_content_type
t.integer :csv_file_size
t.timestamps
end
@raecoo
raecoo / override-footer-of-activeadmin.rb
Last active February 22, 2016 16:58
override footer of ActiveAdmin
@raecoo
raecoo / media-queries.scss
Created July 8, 2014 01:28
Sass Media Queries
// ref: http://paranoida.github.io/sass-mediaqueries/
@media only screen and (-webkit-min-device-pixel-ratio: 1.3), only screen and (min--moz-device-pixel-ratio: 1.3), only screen and (-o-min-device-pixel-ratio: 1.3 / 1), only screen and (min-resolution: 125dpi), only screen and (min-resolution: 1.3dppx) {
// special defined
}
// iPad
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
// special defined
@raecoo
raecoo / bootstrap-modal-center.js
Created July 12, 2014 03:34
Bootstrap Modal Vertically Center
function centerModal() {
$(this).css('display', 'block');
var $dialog = $(this).find(".modal-dialog");
var offset = ($(window).height() - $dialog.height()) / 2;
// Center modal vertically in window
$dialog.css("margin-top", offset);
}
$('.modal').on('show.bs.modal', centerModal);
$(window).on("resize", function () {
@raecoo
raecoo / Capfile
Last active August 29, 2015 14:05
Nginx + Unicorn + Capistrano 2 deploy script
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy'
@raecoo
raecoo / install-redis.sh
Created August 29, 2014 00:51
Install Redis on Amazon EC2 AMI
# chmod 777 install-redis.sh
# ./install-redis.sh
###############################################
echo "*****************************************"
echo " 1. Prerequisites: Install updates, set time zones, install GCC and make"
echo "*****************************************"
sudo yum -y update
#sudo ln -sf /usr/share/zoneinfo/America/Los_Angeles \/etc/localtime
sudo yum -y install gcc gcc-c++ make
echo "*****************************************"
.btn-group-radio input[type=radio] {
visibility: hidden;
position: absolute !important;
top: -9999px !important;
left: -9999px !important;
}
.btn-group-radio input[type=radio]:checked + .btn {
color: #333333;
background-color: #e6e6e6;
@raecoo
raecoo / thunk.rb
Created September 16, 2014 02:35
Remove useless whitespace by Lambda
thunk = lambda do |key,value|
case value
when String then value.strip!
when Hash then value.each(&thunk)
when Array then value.each {|vv| vv.strip!}
end
end
[Hash].each(&thunk)
@raecoo
raecoo / button.coffee
Created September 19, 2014 08:12
customized upload button with Bootstrap 3.x
$(document).on "change", ".btn-file :file", ->
input = $(this)
label = input.val().replace(/\\/g, "/").replace(/.*\//, "")
input.trigger "fileselect", [label]
$(document).on "fileselect", ".btn-file :file", (event, label) ->
$('span.spinner').toggleClass('hide')
$('#upload-form').submit();