Skip to content

Instantly share code, notes, and snippets.

View asaaki's full-sized avatar
🦀
I may be slow to respond. Ping me on Twitter instead: https://twitter.com/asaaki

Christoph Grabo asaaki

🦀
I may be slow to respond. Ping me on Twitter instead: https://twitter.com/asaaki
View GitHub Profile
@asaaki
asaaki / pygments-monokai.css
Created June 4, 2011 00:57
Jekyll module for github like source code highlighting
.highlight { background-color: #49483e }
.c { color: #75715e } /* Comment */
.err { color: #960050; background-color: #1e0010 } /* Error */
.k { color: #66d9ef } /* Keyword */
.l { color: #ae81ff } /* Literal */
.n { color: #f8f8f2 } /* Name */
.o { color: #f92672 } /* Operator */
.p { color: #f8f8f2 } /* Punctuation */
.cm { color: #75715e } /* Comment.Multiline */
.cp { color: #75715e } /* Comment.Preproc */
@asaaki
asaaki / README
Created July 18, 2011 18:50 — forked from peterc/README
testrocket (origin by peterc)
TestRocket is a simple, tiny testing library for Ruby 1.9.
If => in a hash is a "hash rocket", then +-> and --> for tests should be
"test rockets"!
Simple syntax:
+-> { block that should succeed }
--> { block that should fail }
@asaaki
asaaki / unary-oddities.rb
Created July 21, 2011 17:30
Ruby Unary operator overloading and it's oddities
### The 4 unaries are: + - ~ !
### If you really found more, tell me ;o)
class Foo
def +@
puts "unary plus (in front of object) / without param"
end
def -@(a=42)
# please tell me, how could I pass an argument to an unary operation?
# but it's possible to define arguments, curious ...
@asaaki
asaaki / config.ru
Created March 8, 2012 00:15
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
# Run this file with `RAILS_ENV=production rackup -p 3000 -s thin`
# Be sure to have rails and thin installed.
require "rubygems"
# We are not loading Active Record, nor the Assets Pipeline, etc.
# This could also be in your Gemfile.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
# The following lines should come as no surprise. Except by
@asaaki
asaaki / sort_array_by_other_array.rb
Created August 28, 2012 16:10
Sort an array of keys with an array of order
# input data
sort = [ 3, 1, 4, 2 ]
ary = [ :a, :b, :c, :d ]
# the index value should be in result, too (with id+1 because they can be DB indices)
### sort array represents **position** of item in `ary`
#
@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",
]
@asaaki
asaaki / pre-commit
Last active December 11, 2015 12:58
Exports *.bmml files to PNGs when staged for git commit
#!/bin/sh
# .git/hooks/pre-commit
#
# NEEDS registered version of Balsamiq Mockups (mandatory for PNG export)
#
# Exports *.bmml files to PNGs, but only for new or modified ones (files in stage area).
# This should be installed as .git/hooks/pre-commit in your local repository (with +x flag).
# As git hook it ensures that your new/modified (and staged) files will be exported before commit
# your changes to the repository automatically.
@asaaki
asaaki / shell-script-snippets.sh
Last active December 16, 2017 01:48
Shell Snippets
#!/usr/bin/sh
# Count lines of multiple files (recursively):
find source_dir -name "*.ext" -exec wc -l {} +
# 7 digit sha1 transformed timestamp name:
### simple: date +%s%N | \
### more unique
/usr/lib/systemd/systemd-timestamp | \
sha1sum | \
@asaaki
asaaki / date_util.erl
Last active December 28, 2015 13:19 — forked from zaphar/date_util.erl
-module(date_util).
-compile(export_all).
epoch() ->
now_to_seconds(now())
.
epoch_hires() ->
now_to_seconds_hires(now())
.