Skip to content

Instantly share code, notes, and snippets.

@vladimir-e
vladimir-e / gist:10231014
Created April 9, 2014 06:15
Snoop on the program when it's running to see what files and ports are open #osx #macos
sudo lsof | grep AppName | grep -v Applications
@vladimir-e
vladimir-e / randomstr.js
Last active August 29, 2015 13:58
Random string JS
(Math.random() + 1).toString(36).substring(2);
@vladimir-e
vladimir-e / find.rb
Last active August 29, 2015 13:58
Find record with zero has_many records associated #rails #activerecord (http://stackoverflow.com/questions/9613717/rails-find-record-with-zero-has-many-records-associated)
Photoset.includes(:photos).where(photos: {photoset_id: nil})
@vladimir-e
vladimir-e / application.js.coffee
Created May 5, 2014 16:10
Add CSRF token to request headers when using JS framework with rails
$ ->
token = $('meta[name="csrf-token"]').attr('content')
$.ajaxPrefilter (options, originalOptions, xhr) ->
xhr.setRequestHeader('X-CSRF-Token', token)
@vladimir-e
vladimir-e / vps.md
Last active June 10, 2016 18:48
Deploy Rails 4 app to Ubuntu VPS using capistrano 3 (rbenv/puma)

Server Commands

apt-get -y update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties vim mc ImageMagick

# nginx
add-apt-repository ppa:nginx/stable
apt-get -y update
apt-get -y install nginx
@vladimir-e
vladimir-e / nginx.sh
Created June 12, 2014 22:09
nginx error digitalocean when adding second virtual host
sudo service nginx configtest
* Testing nginx configuration [fail]
sudo nginx -t
nginx: [emerg] could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32
nginx: configuration file /etc/nginx/nginx.conf test failed
server_names_hash_bucket_size = 64
sudo service nginx restart
@vladimir-e
vladimir-e / gsub.rb
Last active August 29, 2015 14:02
capture regex pattern with ruby gsub
str = "number 5"
str.gsub(/number\ (\d+)/, '#\1')
# => "#5"
@vladimir-e
vladimir-e / vsftpd.sh
Last active August 29, 2015 14:02
install vsftpd ubuntu #ftp
sudo apt-get install vsftpd
sudo vim /etc/vsftpd.conf
# Uncomment #local_umask=022
sudo service vsftpd restart
@vladimir-e
vladimir-e / seeds.rb
Created June 26, 2014 04:39 — forked from seyhunak/seeds.rb
Rails - Import SQL file as seed
unless Rails.env.production?
connection = ActiveRecord::Base.connection
connection.tables.each do |table|
connection.execute("TRUNCATE #{table}") unless table == "schema_migrations"
end
sql = File.read('db/import.sql')
statements = sql.split(/;$/)
statements.pop
@vladimir-e
vladimir-e / example_controller.rb
Created August 11, 2014 09:00
Orderable concern rails 3
class Admin::SizesController < Admin::AdminController
include OrderableController
end