Skip to content

Instantly share code, notes, and snippets.

View enyachoke's full-sized avatar

Emmanuel Nyachoke enyachoke

View GitHub Profile
= simple_form_for @post, html: { class: 'form-horizontal' }, defaults: { wrapper: :horizontal_form } do |f|
= f.error_notification
.form-inputs
= f.input :first_name
= f.input :last_name
= f.input :email
.form-actions
= f.button :submit
@enyachoke
enyachoke / pre-receive
Created November 13, 2013 20:43
This is a git pre-recieve hook that compiles a slug using heroku buildpacks and optionally uploads it to s3 and generate a pre-signed url for downloading it. This script assumes you have s3cmd installed and configured.
#!/bin/bash
while read oldrev newrev refname
do
# Only build the master branch.
if [[ $refname = "refs/heads/master" ]] ; then
echo "building------> $newrev ... "
#We get the archive and pass it to the slug builder
slug_id=newapp
git archive $newrev | docker run -i -name $newrev -a stdin -a stdout -a stderr flynn/slugbuilder - > $newrev.tgz
# s3cmd put $newrev.tgz s3://pyxiscloud/$newrev.tgz
[
%% Riak CS configuration
{riak_cs, [
%% == Basic Configuration ==
%% Riak CS http/https port and IP address to listen at
%% for object storage activity
{cs_ip, "127.0.0.1"},
{cs_port, 8080 } ,
#!/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