Skip to content

Instantly share code, notes, and snippets.

@happypeter
happypeter / happycasts_deploy.sh
Last active October 10, 2015 04:38
deploy happycasts on my linode vps
#!/usr/bin/env bash
ssh -t peter@happycasts.net '
source ~/.bash_login && cd ~/happycasts && \
git pull && \
bundle exec rake db:migrate RAILS_ENV=production; \
bundle && bundle exec rake assets:precompile &&\
touch tmp/restart.txt
'
@priyaaank
priyaaank / api.rb
Created October 21, 2012 09:32
Modular APIs with Grape and Rails
class API < Grape::API
format :json
error_format :json
version 'v1', :using => :header, :vendor => "App"
rescue_from Mongoid::Errors::DocumentNotFound do |error|
rack_response({"error" => {"message" => "We didn't find what we were looking for"}}.to_json, 404)
end
@bhang
bhang / supervisord_graphite_statsd.conf
Created June 27, 2012 13:45
Graphite + statsd supervisord configuration
[program:gunicorn-graphite]
command=/usr/local/bin/gunicorn_django -u www-data -g www-data -b 127.0.0.1:8080 --log-file=/opt/graphite/storage/log/webapp/gunicorn.log /opt/graphite/webapp/graphite/settings.py
process_name=%(program_name)s
autostart=true
autorestart=true
stopsignal=QUIT
user=www-data
[program:carbon-cache]
command=python /opt/graphite/bin/carbon-cache.py --debug start
@yigitbacakoglu
yigitbacakoglu / gist:ba653c2c5a0ed47d06ba
Last active January 31, 2016 09:41
unicorn - nginx - ssl
upstream unicorn {
server unix:/tmp/unicorn.bthlabs.sock fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
# server_name example.com;
root /index;
@happypeter
happypeter / db_backup.sh
Created June 27, 2012 12:04
db backup with git
#!/usr/bin/env bash
ssh linode 'cd local_clone; cd happynewsdb; \
mysqldump --extended-insert=FALSE --complete-insert=TRUE -uroot authlove_development>authlove_development.sql; \
git commit -a -m"i"; \
git push;\
cd ../happyecdb/ ; \
mysqldump --extended-insert=FALSE --complete-insert=TRUE -uroot ec_development>ec_development.sql; \
git commit -a -m"i"; \
git push;\
@cre-o
cre-o / gist:4535005
Last active February 13, 2016 05:20
Whenever "/usr/bin/env: ruby: No such file or directory" fix
> Tested on ubuntu 12.04 if rvm installed for single user
$ echo $PATH # Since cron doesn't have user's local environment, we need to specify it
$ echo $GEM_PATH # Copy this output to
# Modify schedule.rb with your new PATH's
# It should be like this one (add it to the top)
env :PATH, '/home/home_user/.rvm/gems/ruby-1.9.3-head/bin:/home/home_user/.rvm/gems/ruby-1.9.3-head@global/bin:/home/home_user/.rvm/rubies/ruby-1.9.3-head/bin:/home/home_user/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/home_user/.rvm/bin'
env :GEM_PATH, '/home/home_user/.rvm/gems/ruby-1.9.3-head@gemset:/home/home_user/.rvm/gems/ruby-1.9.3-head@global'
# Now update you crontab file
@nightire
nightire / Rails 4 - Active Record Associations.md
Last active March 27, 2016 12:40
Rails 4 - Active Record Associations

Rails 4 - Active Record Associations

has_one

一对一关系:有 A 和 B,A 拥有且仅拥有一个 B

has_one

belongs_to

@williamherry
williamherry / hubot-explore.md
Last active April 1, 2016 16:24
Hubot Explore

安装

Hubot需要Node和npm的比较新的版本,Mac os x安装非常简单,从nodejs.org下载安装就可以了

➜  node --version
v0.12.4
➜ npm --version
@williamherry
williamherry / bearychat-webhook.coffee
Last active April 2, 2016 14:46
集成到倍洽(bearychat)的hook代码
{TextMessage} = require '../node_modules/hubot/src/message'
module.exports = (robot) ->
robot.router.post '/hubot/bearychat/:room', (req, res) ->
data = if req.body.payload? then JSON.parse req.body.payload else req.body
robot._send ?= robot.adapter.send;
robot.adapter.send = (user,strings...) ->
res.send {text: strings.toString()} if user.user.name is "http"
robot.adapter.send = robot._send if user.user.name isnt "http"
@timoxley
timoxley / Readme.md
Last active June 7, 2016 07:27
JS Pop Quiz: How well do you know your functions?

JS Pop Quiz: How well do you know your functions?

Given an Array of Functions fns, what argument(s) can you pass to fns.forEach such that each function in fns will execute, in order, without creating any anonymous (or named) functions or invoking the Function constructor?

Conditions

  • Do not use the function keyword, or arrow functions () => .
  • Do not invoke the Function constructor.
  • Do not use method definitions.
  • Function#bind & friends on the Function.prototype are ok.