Skip to content

Instantly share code, notes, and snippets.

View enyachoke's full-sized avatar

Emmanuel Nyachoke enyachoke

View GitHub Profile
#!/bin/bash
# a post-receive hook for git servers to tar the current repo and send to s3 for backup
# save as 'post-receive' and put it in .git/hooks of desired repo(s), chmod +x
# assumes you have the s3cmd program installed and configured (sudo apt-get install s3cmd)
echo "thanks for the push. have a nice day."
# configure your S3BUCKET name, the rest should be automatic
-- You need to create plpython languaje in the database
-- createlang -U postgres plpythonu DATABASE_NAME
-- this small trigger prevents an user exceeds a database size. Once the user exceeds the quota
-- the database size is checked every time an update or insert are performed until the user deletes some data
-- If the server is restarted the quota is checked the fist time user executes some update or insert
CREATE OR REPLACE FUNCTION check_quota() RETURNS trigger AS
$$
c = SD.get('quota_counter', 0)
if c%1000 == 0:
#app/inputs/collection_check_boxes_input.rb
class CollectionCheckBoxesInput < SimpleForm::Inputs::CollectionCheckBoxesInput
def item_wrapper_class
"checkbox-inline"
end
end
# http://stackoverflow.com/questions/14972253/simpleform-default-input-class
# https://github.com/plataformatec/simple_form/issues/316
inputs = %w[
CollectionSelectInput
DateTimeInput
FileInput
GroupedCollectionSelectInput
NumericInput
PasswordInput
#Deploy and rollback on Heroku in staging and production
task :deploy_staging => ['deploy:set_staging_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
task :deploy_production => ['deploy:set_production_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
namespace :deploy do
PRODUCTION_APP = 'YOUR_PRODUCTION_APP_NAME_ON_HEROKU'
STAGING_APP = 'YOUR_STAGING_APP_NAME_ON_HEROKU'
task :staging_migrations => [:set_staging_app, :push, :off, :migrate, :restart, :on, :tag]
task :staging_rollback => [:set_staging_app, :off, :push_previous, :restart, :on]
@enyachoke
enyachoke / Gemfile
Created August 10, 2013 07:13 — forked from cblunt/Gemfile
# ...
gem 'carrierwave'
gem 'fog', '~> 1.0.0' # Need to specify version, as carrierwave references older (0.9.0) which doesn't allow configuration of Rackspace UK Auth URL
#Session controller provides a token
#/controllers/api/sessions_controller.rb
class Api::SessionsController < Devise::SessionsController
before_filter :authenticate_user!, :except => [:create]
before_filter :ensure_params_exist, :except => [:destroy]
respond_to :json
def create
resource = User.find_for_database_authentication(:email => params[:user_login][:email])
return invalid_login_attempt unless resource
@PageSpinner =
spin: (ms=500)->
@spinner = setTimeout( (=> @add_spinner()), ms)
$(document).on 'page:change', =>
@remove_spinner()
spinner_html: '
<div class="modal hide fade" id="page-spinner">
<div class="modal-head card-title">Please Wait...</div>
<div class="modal-body card-body">
<i class="icon-spinner icon-spin icon-2x"></i>
@enyachoke
enyachoke / 01_step.sh
Last active December 20, 2015 07:39 — forked from Mikke/01_step.sh
Rails many to many example using checkboxes and multiselelect
rails g scaffold Book title:string description:text
rails g scaffold Pubhouse title:string address:text
rails g model BookPubhouse book_id:integer pubhouse_id:integer
rake db:migrate
# Run with: rake environment elasticsearch:reindex
# Begins by creating the index using tire:import command. This will create the "official" index name, e.g. "person" each time.
# Then we rename it to, e.g. "person20121001" and alias "person" to it.
namespace :elasticsearch do
desc "re-index elasticsearch"
task :reindex => :environment do
klasses = [Place, Person, Caption]