Skip to content

Instantly share code, notes, and snippets.

View FredrikAugust's full-sized avatar
🦦
Otters enjoy spending time in water.

Fredrik A. Madsen-Malmo FredrikAugust

🦦
Otters enjoy spending time in water.
View GitHub Profile
@FredrikAugust
FredrikAugust / color_thing.rb
Created April 12, 2016 19:35
Color thing wo/ GUI
#!/home/greg/.rvm/rubies/default/bin/ruby
require 'rmagick'
# monkeypatch string to convert bases
class String
def convert_base(from, to)
to_i(from).to_s(to)
end
end
@FredrikAugust
FredrikAugust / main.rb
Created May 9, 2016 14:18
Next EA bestseller
#!/home/greg/.rvm/rubies/default/bin/ruby
require 'gosu'
# main class for the laser element in game
class Laser
attr_reader :created_at, :x, :y, :created_by
def initialize(window_size, angle, player)
@window_size = window_size
@FredrikAugust
FredrikAugust / flatten.js
Created November 18, 2016 10:25
Flatten an array in javascript
Array.prototype.flatten = function () {
var flat_arr = [];
var dirty = false;
for (var i = 0; i < this.length; i++) {
if (typeOf(this[i]) == "array") {
flat_arr = flat_arr.concat(this[i]);
dirty = true;
} else {
flat_arr.push(this[i]);
@FredrikAugust
FredrikAugust / euclidean_distance.rb
Created January 30, 2017 13:26
Euclidean distance in Ruby (2-dimensional)
# Euclidean distance in ruby (2-dimensional)
# The points have to be in the format [x, y]
def euclidean_distance(point1, point2)
# First; group the x's and y's, then sum the squared difference in x's and y's
Math.sqrt(point1.zip(point2).reduce(0) { |sum, p| sum + (p[0] - p[1]) ** 2 })
end
@FredrikAugust
FredrikAugust / xevkey.sh
Created February 5, 2017 18:09
get key name - xev
#!/bin/bash
xev | grep -Po '\(keysym\s[^)]+,\s\K([^\)]+)'
@FredrikAugust
FredrikAugust / .gitignore
Last active February 14, 2017 08:19
jwtgoauth.go
public
@FredrikAugust
FredrikAugust / rps.rb
Last active February 17, 2017 14:28
Rock paper scissor in ruby, 232 bytes
p 'Would you like to play a game?'
abort 'I hope to play sometime' unless gets.chomp.upcase.ord==89
p 'Rock, paper or scissors?'
p (s=(a={82=>83,80=>82,83=>80}).keys.sample)==(i=gets.upcase.ord) ? 'Tie' : (a[i]==s ? 'Win' : 'Loss')
@FredrikAugust
FredrikAugust / wallpaper.sh
Created February 27, 2017 22:17
Set a random wallpaper from unsplash with 1920x1080 resolution
#!/bin/bash
wget https://source.unsplash.com/random/1920x1080 -O ~/.wallpaper.jpg
feh --bg-fill ~/.wallpaper.jpg
package main
import (
"fmt"
"github.com/fogleman/gg"
"math/rand"
)
func randomFromDistribution(distribution []float64) int {
randFloat := rand.Float64()
function $(value) {
return document.querySelector(value);
}
const canvas = $('canvas');
const sets = [
[-0.4, 0.0, 0.0, -0.4, -1.0, 0.1],
[0.76, -0.4, 0.4, 0.76, 0.0, 0.0]
];