This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
class ApplicationController < ActionController::Base | |
protect_from_forgery | |
rescue_from Exception, :with => :handle_exceptions | |
private | |
def handle_exceptions(e) | |
case e | |
when CanCan::AccessDenied |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# responds to requests with Forsyth-Edwards notation in URL with an image: | |
# http://dia-x.info/fen/2S5/1bQKpR2/4s3/2bkpP2/Sr1p2r1/1P1R3B/1B2s3/8 | |
# | |
class FenController < ApplicationController | |
include Magick |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_RUBY=ruby-1.9.3 | |
_PROJECT=dia-x | |
export rvm_gem_options="--no-rdoc --no-ri" | |
if [[ -s "${rvm_path:-$HOME/.rvm}/environments/$_RUBY@$_PROJECT" ]] | |
then | |
. "${rvm_path:-$HOME/.rvm}/environments/$_RUBY@$_PROJECT" | |
else | |
rvm --create use "$_RUBY@$_PROJECT" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
[[ $1 =~ ([[:alnum:]]+)-([[:alnum:]]+) ]] || exit 1 | |
[[ "$2" = suffix ]] && | |
echo ${BASH_REMATCH[2]} && exit 0 | |
echo ${BASH_REMATCH[1]} && exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getImageSize = (image, cb) -> | |
fromHex = (hex) -> parseInt "0x#{hex}", 16 | |
req = http.request image, (res) -> | |
res.setEncoding 'hex' | |
res.on 'error', (e) -> cb "getImageSize error (#{image}): " + e, null, image | |
res.on 'data', (chunk) -> | |
m = switch res.headers['content-type'] | |
when 'image/jpeg' | |
chunk.match 'ffc0001108(....)(....)' | |
when 'image/png' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
indexB: -> | |
x = fs.readFileSync xmlInput | |
parser.parseString x, (error_xml, res_xml) -> | |
for product in res_xml?.products?.product[0..0] | |
r = request | |
uri: S.Found.uri + '/stock/one' | |
method: 'POST' | |
json: product | |
r.pipe process.stdout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bases = require('bases'); | |
var crypto = require('crypto'); | |
// Returns a base-62 (alphanumeric only) string of the given length: | |
function randomStr(length) { | |
// We generate a random number in a space at least as big as 62^length, | |
// and if it's too big, we just retry. This is still statistically O(1) | |
// since repeated probabilities less than one converge to zero. Hat-tip to | |
// a Google interview for teaching me this technique! ;) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Delete branches not tracked by remote | |
git remote prune origin | |
# Prettier log | |
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ike@osaka:~$ cat /etc/nginx/sites-available/node-configly | |
server { | |
listen 80; | |
server_name www.config.ly; | |
location / { | |
proxy_pass http://unix:/var/run/proxy.sock/node-configly.80:$uri$is_args$args; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; |
OlderNewer