Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / randomstr.js
Last active August 29, 2015 13:58
Random string JS
(Math.random() + 1).toString(36).substring(2);
@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 / amortization_calculator.js.coffee
Created January 10, 2014 10:18
Amortization Calculator (accounting project)
#
# @author Vladimir E <[email protected]>
#
class Finliner.Models.AmortizationCalculator extends Finliner.Models.BaseModel
available_methods: [
"linear_period" # Линеийный способ (от срока)
"linear_percent" # Линеийный способ (от процента)
"residual_reducing" # Способ уменьшения остатка
"years_amount" # По сумме чисел лет
@vladimir-e
vladimir-e / fixpostgis.sh
Created January 3, 2014 07:36
Can't create postgis extension in postgres (geometry field)
postgres=# create extension if not exists postgis;
ERROR: could not load library "/usr/local/Cellar/postgresql/9.3.2/lib/rtpostgis-2.1.so": dlopen(/usr/local/Cellar/postgresql/9.3.2/lib/rtpostgis-2.1.so, 10): Library not loaded: /usr/local/opt/sqlite/lib/libsqlite3.0.8.6.dylib
Referenced from: /usr/local/lib/libspatialite.5.dylib
Reason: image not found
# Solution is to create symlink to sqlite with "the right" name
ln -s /usr/local/opt/sqlite/lib/libsqlite3.0.dylib /usr/local/opt/sqlite/lib/libsqlite3.0.8.6.dylib
@vladimir-e
vladimir-e / support_cyrillic.sh
Created December 11, 2013 03:41
Support cyrillic / russian input in rails console and IRB
$ brew install openssl readline
$ CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl` --with-readline-dir=`brew --prefix readline`" rbenv install 2.0.0-p353
@vladimir-e
vladimir-e / show_hidden.sh
Created November 3, 2013 18:19
Display all files in finder - to restore hidden file from time machine
defaults write com.apple.finder AppleShowAllFiles TRUE
# restart finder in alt+cmd+esc dialog window
@vladimir-e
vladimir-e / gist:7024773
Last active December 25, 2015 18:59
init postgres
initdb /usr/local/var/postgres -E utf8 # create a database cluster
postgres -D /usr/local/var/postgres # serve that database
PGDATA=/usr/local/var/postgres postgres # …alternatively
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
https://github.com/mxcl/homebrew/issues/issue/2510
To migrate existing data from a previous major version (pre-9.3) of PostgreSQL, see:
http://www.postgresql.org/docs/9.3/static/upgrading.html
@vladimir-e
vladimir-e / gist:6711434
Created September 26, 2013 08:34
Reload / refresh page #backbone #bb
Backbone.history.loadUrl