Skip to content

Instantly share code, notes, and snippets.

View akwiatkowski's full-sized avatar

Aleksander Kwiatkowski akwiatkowski

View GitHub Profile
@lbarasti
lbarasti / normal_distribution.cr
Last active May 4, 2020 14:13
Sampling random variables and plotting histograms in Crystal
require "statistics"
require "ishi"
require "tablo"
include Statistics::Distributions
# Turns a named tuple into tabular representation
def table(data : NamedTuple)
Tablo::Table.new(data.map { |k, v| [k, v] }, header_frequency: nil) { |t|
t.add_column("coefficient") { |n| n[0] }
Assume X-Y bounding box: [-1, 1]*[-1, 1] -> 2*2 size
Orthographic camera scale: 2*sqrt(2)=2.82843
Camera X, Y: (1, 1)
Camera Z: 2*sqrt(2)*tan(30deg)=1.63299 (<- looking at (-1, -1, 0) from (1, 1, Z))
Camera Rot: (60deg, 0deg, 135deg)
@spalladino
spalladino / main.cr
Last active November 29, 2016 23:31
Alternative code for "Crystal in real life" post
# Adapted from http://pfertyk.me/2016/11/crystal-in-real-life/
require "stumpy_png"
canvas = StumpyPNG.read("image.png")
canvas.width.times do |x|
canvas.height.times do |y|
color = canvas[x, y]
@madsheep
madsheep / kitten_mailer.rb
Created September 10, 2013 14:58
Any mailer inherited from this one will have random cat included as an attachment.
class KittenMailer < ActionMailer::Base
def mail *args
attachments['cat.jpeg'] = open("http://placekitten.com/#{rand(300)+300}/#{rand(300)+300}").read
super
end
end
@matthewryanscott
matthewryanscott / gist:2913909
Created June 12, 2012 01:50
Installing retroshare on Debian Squeeze
This is what worked for me to install it on Squeeze 64-bit:
$ sudo aptitude install libqt4-dev g++ libgpgme11-dev libgpg-error-dev libupnp-dev libssl-dev libgnome-keyring-dev libxss-dev gnupg-agent
If this asks you to remove packages, DO NOT CONTINUE. The above line should only INSTALL packages. Fix your system first.
$ wget http://sourceforge.net/projects/retroshare/files/RetroShare/0.5.3c/RetroShare-v0.5.3c.tar.gz/download
$ tar xzvf RetroShare-v0.5.3c.tar.gz
$ cd trunk/libbitdht/src
$ qmake && make
@alexpc
alexpc / rubywrap.sh
Created April 17, 2012 13:00
Small wrapper for Ruby scripts running on RVM Single-User installations
#!/bin/bash
# Change those for valid ones
HOMEDIR=/home/yourlogin
RUBYVER="1.9.2-p318"
# Adding to $PATH paths for rvm and ruby executables
PATH=$PATH:$HOMEDIR/.rvm/bin:$HOMEDIR/.rvm/rubies/ruby-$RUBYVER/bin/
# Creating variable containing path to installed gems
RUBYLIB=$HOMEDIR/.rvm/gems/ruby-$RUBYVER/gems/:$HOMEDIR/.rvm/gems/ruby-$RUBYVER@global/gems/
@johnjohndoe
johnjohndoe / vimeo.com.ffpreset
Created December 15, 2011 01:18
FFmpeg settings for vimeo.com
// FFmpeg settings for vimeo.com
// =============================
// Trying to find the best settings for encoding videos as described here: http://vimeo.com/help/compression
//
// Input file: MTS
// Video: H264, 1920x1080, 50fps
// Audio: A52 Audio (aka AC3), Stereo, 48kHz, 256kbps
ffmpeg -i input.mts -vcodec libx264 -acodec aac -strict experimental -vpre hq -s hd720 -b 5000k -ab 320k -r 25 -g 25 -threads 0 output.mp4
@samnang
samnang / rails31init.md
Created September 3, 2011 16:27 — forked from docwhat/rails31init.md
Rails 3.1 with Rspec, Factory Girl, Haml, Simple Form, Database Cleaner, Spork, and Guard

Install Rails 3.1

gem install rails

generate new app, skipping Test::Unit file generation

rails new my_app -T

Set up Gemfile

@rsanheim
rsanheim / gist:1054078
Created June 29, 2011 15:23
Devise + Spork + Rails 3.1 RC4 hacks to keep User model from loading prefork
Spork.prefork do
require "rails/application"
# Prevent Devise from loading the User model super early with it's route hacks for Rails 3.1 rc4
# see also: https://github.com/timcharper/spork/wiki/Spork.trap_method-Jujutsu
Spork.trap_method(Rails::Application, :reload_routes!)
Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
# rest of your prefork here...
end
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')