Skip to content

Instantly share code, notes, and snippets.

@DanielApp.module "Entities", (Entities, App, Backbone, Marionette, $, _) ->
App.commands.setHandler "when:fetched", (entities, callback) ->
xhrs = _.chain([entities]).flatten().pluck("_fetch").value()
$.when(xhrs...).done ->
callback()
chain: function() {
collection.fetch()
whenFetched(collection,function() {
...
another_collection.fetch()
whenFetched(another_collection,function() {
...
});
);
},
@sharshenov
sharshenov / gist:965e71881f4e824797df
Last active August 29, 2015 14:04
Postgres setup
sudo apt-get install postgresql-9.3 postgresql-contrib
sudo -u postgres psql
create role USERNAME with password 'PASSWORD';
alter role USERNAME login;
create database DBNAME;
@sharshenov
sharshenov / gist:f4d05ed3a701133a3c35
Last active December 5, 2016 16:45
Nginx config for puma socket
upstream application {
server unix:/home/deploy/apps/APPNAME/shared/tmp/sockets/puma.sock fail_timeout=0;
}
# Optional redirect
#server {
# listen 80;
# server_name www.DOMAIN default;
# return 301 $scheme://DOMAIN$request_uri;
#}
@sharshenov
sharshenov / gist:2ce672c6e584b288d9cd
Last active August 29, 2015 14:05
Setup postfix gmail relay on ubuntu
# YOLO
sudo su
# Install postfix (use Internet Site configuration)
apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
# Setup allowed SSL certs
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | tee -a /etc/postfix/cacert.pem
# Add to /etc/postfix/main.cf
@sharshenov
sharshenov / gist:b8371f4ea4f09318415d
Last active August 29, 2015 14:06
Logrotate template for rails apps
# save as /etc/logrotate.d/APPNAME
/home/deploy/apps/APPNAME/shared/log/*.log {
su deploy deploy
daily
missingok
rotate 30
compress
delaycompress
notifempty
copytruncate
@sharshenov
sharshenov / gist:a34db47c2311acd38c92
Last active June 13, 2016 04:24
add swapfile to ubuntu host
#Original article: https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-12-04
dd if=/dev/zero of=/swapfile bs=1M count=1k
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0 ' >> /etc/fstab
echo 1 | tee /proc/sys/vm/swappiness
echo vm.swappiness = 1 | tee -a /etc/sysctl.conf
chown root:root /swapfile
chmod 0600 /swapfile

Keybase proof

I hereby claim:

  • I am sharshenov on github.
  • I am sharshenov (https://keybase.io/sharshenov) on keybase.
  • I have a public key whose fingerprint is ED36 8D30 17B6 39F8 B58E 1E7D EDF0 0A21 B208 D134

To claim this, I am signing this object:

@sharshenov
sharshenov / gist:b494474ae3a0685f6a2f
Created March 22, 2015 06:23
Set postgresql template1 default charset to UTF-8
# open console as postgres user
sudo -u postgres psql
# paste this
update pg_database set datistemplate = FALSE where datname = 'template1';
drop database template1;
create database template1 with owner=postgres encoding='UTF-8' lc_collate='en_US.utf8' lc_ctype='en_US.utf8' template template0;
update pg_database set datistemplate = TRUE where datname = 'template1';
@sharshenov
sharshenov / gist:a414add41a3bcc219c6e
Created March 24, 2015 07:12
Fix sublimetext closing on Ctrl+W
1. Select Preferences / Key Bindings(user)
2. Paste this:
```json
[
{ "keys": ["ctrl+w"], "command": "close_file" },
]
```