Skip to content

Instantly share code, notes, and snippets.

View enyachoke's full-sized avatar

Emmanuel Nyachoke enyachoke

View GitHub Profile
#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]
# 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
#app/inputs/collection_check_boxes_input.rb
class CollectionCheckBoxesInput < SimpleForm::Inputs::CollectionCheckBoxesInput
def item_wrapper_class
"checkbox-inline"
end
end
-- 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:
#!/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
[
%% 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 } ,
@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
= 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 / DataSource.java
Last active August 29, 2015 14:03
Android bootcamp gists
import java.util.ArrayList;
public class DataSource {
private ArrayList<Integer> mPhotoPool;
private ArrayList<Integer> mQuotePool;
private ArrayList<Integer> mPhotoHdPool;
public ArrayList<Integer> getmPhotoHdPool() {
return mPhotoHdPool;
}
/**
* Showcasing a custom FieldGroupGieldFactory that generates an UploadField(from https://vaadin.com/directory#addon/easyuploads)
* if the FieldGroup is trying to bind to a byte[] object property.
* The image instance is updated each time a new image is uploaded
*
* Ruiu Gabriel Mihai ([email protected])
*/
public class ImageReplacerFieldGroup extends FormLayout {
public ImageReplacerFieldGroup() {