Skip to content

Instantly share code, notes, and snippets.

View larryzhao's full-sized avatar
🐱
Meow

Larry Zhao larryzhao

🐱
Meow
View GitHub Profile
@dustinlarimer
dustinlarimer / index.html
Last active December 30, 2015 16:19
Day/Hour PageView Heatmap for Keen.io
<!DOCTYPE html>
<html>
<head>
<title>PageView Grid</title>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>
<script>
var Keen=Keen||{configure:function(e){this._cf=e},addEvent:function(e,t,n,i){this._eq=this._eq||[],this._eq.push([e,t,n,i])},setGlobalProperties:function(e){this._gp=e},onChartsReady:function(e){this._ocrq=this._ocrq||[],this._ocrq.push(e)}};(function(){var e=document.createElement("script");e.type="text/javascript",e.async=!0,e.src=("https:"==document.location.protocol?"https://":"http://")+"dc8na2hxrj29i.cloudfront.net/code/keen-2.1.0-min.js";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)})();
Keen.configure({
projectId: "<your-projectId>",
@malditogeek
malditogeek / gist:3156358
Created July 21, 2012 16:36
Goliath + HAProxy deploy recipe
after "deploy:update", "deploy:cleanup"
after "deploy:update", "foreman:export"
after "deploy:symlink", "update_haproxy_config_symlink"
namespace :deploy do
task :stop do
run "sudo stop goliath_app"
end
task :start do
run "sudo start goliath_app"
@sdrew
sdrew / HTTP-Status-Codes.md
Last active May 19, 2017 13:30
Mapping of HTTP Status Codes to Symbols in Rails, as found here: http://www.codyfauser.com/2008/7/4/rails-http-status-code-to-symbol-mapping

1xx Informational

Status Code Status Message Symbol
100 Continue :continue
101 Switching Protocols :switching_protocols
102 Processing :processing

2xx Success

@johnantoni
johnantoni / unicorn.rb
Created August 2, 2012 15:48
unicorn + nginx setup + ssl
unicorn.rb
-----------------------------------
application = "jarvis"
remote_user = "vagrant"
env = ENV["RAILS_ENV"] || "development"
RAILS_ROOT = File.join("/home", remote_user, application)
worker_processes 8
timeout 30
@schneems
schneems / gist:c07d93d5a4ade679bbc3
Last active May 15, 2018 09:38
Puma Backlog Setting on Heroku

Why not set backlog on Heroku?

First read this: https://mikecoutermarsh.com/adjusting-pumas-backlog-for-heroku/

Now we're on the same page. Heroku will re-route bounced requests from your dynos but it assumes when this happens that your entire app is saturated. https://devcenter.heroku.com/articles/http-routing#dyno-connection-behavior. Each connection gets delayed by 5 seconds, so you're automatically being docked 5 seconds per request.

If you're setting your backlog to a low value (i.e. if you'll ever actually ever hit backlog) then you'll be in for pain. When you get a spike of requests from slashdot/reddit/whatever you're telling your dynos that you would rather they failed then returned slow responses. So this does mean that some requests will be served, but all the others will fail.

If your app ever hits your backlog (no matter what value it is) it is an indicator you don't have enough throughput and you need to scale out to more dynos. If you set this to an arbitrarilly low value, that point comes

require 'eventmachine'
require 'socket'
require 'kgio'
server = Kgio::TCPServer.new('0.0.0.0', 4242)
module Dispatch
def notify_readable
io = @io.kgio_tryaccept or return
EventMachine.attach(io, Server)
@rwjblue
rwjblue / output.txt
Created March 2, 2013 16:43
Test Ruby's ability to release memory back to system.
Ruby 1.9.3-p392
===========================================================
All memory used before 1st run - 7 MB
Memory consumed by 1st run of eat_up_memory - 445 MB
All memory used before 2nd run - 452 MB
Memory consumed by 2nd run of eat_up_memory - 20 MB
All memory used before 3rd run - 472 MB
Memory consumed by 3rd run of eat_up_memory - 5 MB
Memory used before explicit GC.start - 478 MB
Memory used after explicit GC.start - 284 MB
@chriseppstein
chriseppstein / readme.md
Created August 31, 2011 21:57 — forked from mislav/Gemfile
How to integrate Compass with Rails 3.1 asset pipeline

This gist is no longer valid. Please see Compass-Rails for instructions on how to install.

@jeffreyiacono
jeffreyiacono / Rakefile
Created February 8, 2012 20:15
rake task for precompiling assets using sprockets within a sinatra app + view helpers
require 'rubygems'
require 'bundler'
Bundler.require
require './application'
namespace :assets do
desc 'compile assets'
task :compile => [:compile_js, :compile_css] do
end
@elwinar
elwinar / snake.go
Created November 18, 2014 11:30
ToSnake function for golang, convention-compliant
package main
import (
"unicode"
)
// ToSnake convert the given string to snake case following the Golang format:
// acronyms are converted to lower-case and preceded by an underscore.
func ToSnake(in string) string {
runes := []rune(in)