Skip to content

Instantly share code, notes, and snippets.

View aalin's full-sized avatar

Andreas Alin aalin

  • Peru
View GitHub Profile
FROM node:latest
MAINTAINER Andreas Alin
ADD package.json /app/package.json
RUN cd /app && npm install
RUN npm install node-sass
COPY . /app
WORKDIR /app
class Progress
class DefaultFormatter
def progress_format(current, total)
format("\e[K\e[G %5.2f%% (%s / %s)", current / total.to_f * 100.0, format_number(current), format_number(total))
end
def format_number(number)
number.to_s.chars.reverse.each_slice(3).map(&:reverse).reverse.map(&:join).join(" ")
end
end
var TweeningNumber = React.createClass({
mixins: [tweenState.Mixin],
getInitialProps: function() {
return {
value: 0,
duration: 500
};
},
getInitialState: function() {
return { value: 0 };
@aalin
aalin / catmull_rom_splines.rb
Created June 6, 2013 10:55
Catmull-Rom splines implemented in Ruby.
# Based on https://github.com/Sojo-Studios/catmull-rom/blob/master/test.js
# This implementation assumes circular splines.
class CatmullRomSplines
def initialize(points)
@key_points = points
end
def generate(detail)
points = []
@aalin
aalin / gist:5129639
Last active December 14, 2015 18:29
OpenGL screenshots with ChunkyPNG
# This takes about 1.6 seconds for 800x600
def short_screenshot!(width, height)
pixels = glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE)
image = ChunkyPNG::Image.from_rgb_stream(width, height, StringIO.new(pixels))
image.flip_horizontally!
image.save('screenshot.png', :fast_rgb)
end
# This takes about 0.8 seconds for 800x600
def long_screenshot!(width, height)
@aalin
aalin / t_scope.rb
Last active December 11, 2015 13:18 — forked from henrik/t_scope.rb
module I18n
# Usage (Haml in examples):
#
# - t_scope(:"public.sign_up_or_log_in") do |s|
# = simple_format(s.t(:text,
# sign_up: link_to(s.t(:sign_up), signup_path),
# log_in: link_to(s.t(:log_in), login_path)))
#
# is equivalent to
#
@aalin
aalin / schema_dumper_sequences.rb
Created August 23, 2012 12:29
Monkeypatching Rails SchemaDumper to support sequences.
class ActiveRecord::SchemaDumper
def dump(stream)
header(stream)
tables(stream)
sequences(stream)
sequence_defaults(stream)
trailer(stream)
stream
end
# encoding: utf-8
class LocaleDiffer
RED = 31
GREEN = 32
def initialize
load_locales
end
@aalin
aalin / locale_formatter.rb
Created March 22, 2012 17:04
Rails locale formatter
#!/usr/bin/env ruby
# encoding: utf-8
require 'yaml'
require 'stringio'
class LocaleFormatter
ESCAPE_KEYS = %w(true false yes no on off)
ESCAPE_VALUE_RE = /[^[:alnum:]_\-\/\.\?]/
MULTILINE_INDENT_LEVEL = 2
@aalin
aalin / gist:1816302
Created February 13, 2012 11:56
headache when installing capybara-webkit
# changed line 19 of rubygems/ext/builder.rb from:
mf = File.read('Makefile')
# into
mf = File.read('Makefile', :encoding => 'iso-8859-15').encode('utf-8')
# Problem was that qmake generated a Makefile that included a latin 1 "å" in the date because of swedish locales...