Skip to content

Instantly share code, notes, and snippets.

View asaaki's full-sized avatar
🦀
Oh crab!

Christoph Grabo asaaki

🦀
Oh crab!
View GitHub Profile
@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

require 'cgi'
require 'uri'
def get_section_id_from_url(url)
query = URI.parse(url).query
return nil if not query
CGI.parse(query)['section'].first
end
@garlandkr
garlandkr / varnishncsa.json
Last active June 10, 2022 15:48
JSON from varnishncsa
varnishncsa -F '{
"@source" => "unknown",
"@type" => "varnish",
"@fields" => {
"remote_addr"=>"%h",
"remote_user" => "%u",
"x_forwarded_for" => "%{X-Forwarded-For}i",
"hit_miss"=>" %{Varnish:hitmiss}x",
"body_bytes_sent"=>"%b",
"request_time"=>"%{Varnish:time_firstbyte}x",
@zhchbin
zhchbin / index.html
Created February 10, 2013 10:55
Node-Webkit API Demo: Window.capturePage
<html>
<body style="background: #333">
<script >
var gui = require('nw.gui');
var win = gui.Window.get();
function takeSnapshot() {
win.capturePage(function(img) {
var popWindow = gui.Window.open('popup.html',
{width: 420, height: 300});
popWindow.on('loaded', function() {
" Execute :CleanWhitespace to manually clean all trailing whitespace.
command! CleanWhitespace call s:InPlace('%s/\s\+$//e')
" Clean all useless whitespace automatically upon save.
"
" Do a 'let g:clean_whitespace = 0' if you need to avoid this for some reason.
let g:clean_whitespace = 1
autocmd BufWritePre *
\ if g:clean_whitespace |
\ exe "CleanWhitespace" |
@asaaki
asaaki / app.rb
Last active December 11, 2015 05:49
Simple Rack setup where you can move your middleware and map config to another file
App = lambda do |env|
[
200,
{ "Content-Type" => "text/plain" },
[
"Hello!\n",
"self in config.ru is: #{RACK_BUILDER.to_s}\n",
"@use = #{RACK_BUILDER.instance_variable_get(:@use)}\n",
"@map = #{RACK_BUILDER.instance_variable_get(:@map)}\n",
]
class Enum < Hash
def initialize(*members)
super()
@rev = {}
members.each_with_index {|m,i| self[i] = m }
end
def [](k)
super || @rev[k] # || raise ArgumentError, "#{k} is not a member of this enum"
end
def []=(k,v)
@AndrewRadev
AndrewRadev / ack-gems
Created December 20, 2012 14:15
Use 'ack' to search through all the gems in the project. Call with "bundle exec ack-gems".
#! /usr/bin/env ruby
require 'bundler'
paths = Bundler.load.specs.map(&:full_gem_path)
system("ack '#{ARGV[0]}' #{paths.join(' ')}")
@alexjs
alexjs / cors-nginx.conf
Created November 28, 2012 22:42 — forked from michiel/cors-nginx.conf
Slightly tighter CORS config for nginx
#
# Slightly tighter CORS config for nginx
#
# A modification of https://gist.github.com/1064640/ to include a white-list of URLs
#
# Despite the W3C guidance suggesting that a list of origins can be passed as part of
# Access-Control-Allow-Origin headers, several browsers (well, at least Firefox)
# don't seem to play nicely with this.
#
@lucaong
lucaong / README.md
Created November 22, 2012 15:39
Experiment with a nano-library for DOM selection

Usage:

the $query (aliased with $q) object exposes two methods: first() and all(). Both take a selector string as the first argument and, optionally, a context element as the second.

$q.first(".foo"); // => first element of class `foo`
$q.all(".foo");   // => array (yes, not NodeList) of all elements of class `foo`

var elem = $q.first("p");