Skip to content

Instantly share code, notes, and snippets.

View aalin's full-sized avatar

Andreas Alin aalin

  • Peru
View GitHub Profile
#pragma once
#include <glm/glm.hpp>
template<typename T>
class Tween {
public:
Tween(float speed = 1.0)
: _value(T()),
_target(T()),
@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 / gradient.js
Last active September 22, 2017 11:47
function lerp(a, b, t) {
return a + t * (b - a);
}
function mix(a, b, t) {
return a.map((v, i) => lerp(v, b[i], t));
}
function clamp(x, min, max) {
if (x < min) { return min; }
@aalin
aalin / pre-commit
Created August 9, 2017 09:10
Run prettier on staged files
#!/bin/bash
prettier=$(npm bin)/prettier
git diff --cached --name-status src/ | while read -r status filename; do
# skip deleted files
if [[ "$status" == "D" ]]; then continue; fi
if [[ "$filename" =~ \.jsx?$ ]]; then
"$prettier" --single-quote --no-bracket-spacing --write "$filename" || exit 1
'use strict';
const fs = require("fs");
function leftPad(str, length, chr) {
str = str.toString();
if (str.length >= length) {
return str;
}
@aalin
aalin / .irbrc
Created October 8, 2010 10:05
Show rails environment in the rails console
class IRB::Irb
alias :original_prompt :prompt
def prompt(prompt, ltype, indent, line_no)
prompt = prompt.call if prompt.respond_to?(:call)
original_prompt(prompt, ltype, indent, line_no)
end
end
IRB.conf[:PROMPT_MODE] = :RAILS_ENV
IRB.conf[:PROMPT][:RAILS_ENV] = IRB.conf[:PROMPT][:CLASSIC].merge(:PROMPT_I => lambda { (defined?(Rails) ? "#{Rails.env} " : "") + "%N(%m):%03n:%i> " })
@aalin
aalin / lsformat.rb
Created November 29, 2016 22:11
Format files in a table like ls
require 'io/console'
require 'pp'
files = Dir["*"].sort
MAX_COLUMNS = 9
MAX_COLUMNS.downto(1) do |i|
columns = files.each_slice(i).map { |x| Array.new(i) { |n| x[n] } }
rows = columns.transpose
#!/usr/bin/env ruby
require 'shellwords'
FIELDS = %w(artist album name duration spotify\ url).map { |x| "#{x} of current track" }.join(' & "\\n" & ')
SCRIPT =<<EOF
tell application "Spotify"
#{FIELDS}
end tell
# Put this in your project root and create a symlink from ~/.tmuxinator/projectname.yml
name: <%= File.basename(path, '.*') %>
root: <%=
begin
File.dirname(File.readlink(path))
rescue
puts "#{path} should be symlinked from your project root."
exit 1
end
@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)