Skip to content

Instantly share code, notes, and snippets.

View demisx's full-sized avatar

Dmitri demisx

View GitHub Profile
@demisx
demisx / .pryrc | .sh
Last active July 13, 2018 17:03
Hirb & Pry. If you've finally got around to replace your rails default console with pry and want to see Hirb formatted output, add the following code to your ~/.pryrc file (e.g. /home/dmoore/.pryrc)
require 'hirb'
Hirb.enable
old_print = Pry.config.print
Pry.config.print = proc do |output, value|
Hirb::View.view_or_page_output(value) || old_print.call(output, value)
end
@demisx
demisx / sample_gist.rb
Last active January 3, 2016 01:09
Sample ruby gist
def show
puts "Outputting a very lo-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-ong lo-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-ong line"
@widget = Widget(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @widget }
end
end
@demisx
demisx / syntax.css
Last active March 15, 2021 13:42
Jekyll CSS syntax highlighter with improved formatting of code line numbers based on https://github.com/mojombo/tpw/blob/master/css/syntax.css
.highlight { background: #ffffff; }
.highlight .c { color: #999988; font-style: italic } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { font-weight: bold } /* Keyword */
.highlight .o { font-weight: bold } /* Operator */
.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
@demisx
demisx / gist:8960218
Last active August 29, 2015 13:56
Rails generators
# Rails::API app
$ rails-api new [nplate-syjdata-api] --skip-sprockets --skip-test-unit
# Rails app
$ rails new [my-app-name] --skip-test-unit
$ rails generate controller PersonalityTests take results
$ rails g model Foo bar:string baz:integer
$ rails g migration AddWorkflowStateToGraduates workflow_state:string
$ rails g serializer doctor
@demisx
demisx / gist:8965498
Last active August 29, 2015 13:56
Rails migrations integer :limit option
:limit Numeric Type Column Size Max value
--------- ------------ ----------- ----------
1 tinyint 1 byte 127
2 smallint 2 bytes 32767
3 mediumint 3 byte 8388607
nil, 4, 11 int(11) 4 byte 2147483647
5..8 bigint 8 byte 9223372036854775807
Note: by default MySQL uses signed integers, so the max. values noted are for signed integers.
@demisx
demisx / application_controller.rb
Last active August 29, 2015 13:56
Temporary stub current_user method in Rails application
# A convinient way to stub out a current_user method if you are in the middle of development and don't want to add authentication yet:
class ApplicationController < ActionController::Base
...
def current_user
OpenStruct.new(admin?: false)
end
helper_method current_user
@demisx
demisx / gist:9145465
Last active August 29, 2015 13:56
Redis Installation
# Mac OS X
# =========
$ brew install
# To automatically load on login:
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
# To refresh after upgrade:
@demisx
demisx / gist:9203799
Last active August 29, 2015 13:56
Export Postgres table to CSV file
# Exports specified columns from doctors table to nplate_doctors.csv file
$ rails dbconsole
=# COPY doctors(customer_number,address_line_1,address_line_2,address_line_3,city,state,zip_code,primary_phone,prof_first_name,prof_middle_name,prof_last_name,prof_name_prefix,prof_name_suffix,primary_specialty,secondary_specialty,npi,ims,me,primary_specialty_dscr,latitude,longitude) TO '/Users/dmoore/projects/colddata-amgen/nplate_doc_finder/db/seeds/nplate_doctors.csv' DELIMITER ',' CSV HEADER;
@demisx
demisx / gist:9318336
Created March 3, 2014 04:23
Boostrap New Rails API App
1. Generate new rails api structure
# he "-S" options removes the sprockets stuff, we dont need it since we will use Grunt
# for our frontend code. "-T" is because I use RSpec and no need for "test/" directory
$ rails-api new [app_name]-S -T
2. Remove everything from
$ cd [app_name]
$ rm -fr public/*
@demisx
demisx / macosx.sh
Last active December 8, 2017 12:40
Nginx Install
# Mac OS X
# ==============
# Installation
$ brew update
$ brew doctor
$ brew install nginx
$ mkdir -p /usr/local/etc/nginx/sites-{enabled,available}
$ mkdir -p /usr/local/etc/nginx/logs
$ mkdir -p /usr/local/etc/nginx/conf.d