Skip to content

Instantly share code, notes, and snippets.

View peterhellberg's full-sized avatar
💙
Coding Go and Zig

Peter Hellberg peterhellberg

💙
Coding Go and Zig
View GitHub Profile
@peterhellberg
peterhellberg / max_parallelism.go
Created June 24, 2013 07:25
Find out the max value for GOMAXPROCS on your machine.
package main
import (
"fmt"
"runtime"
)
func MaxParallelism() int {
maxProcs := runtime.GOMAXPROCS(0)
numCPU := runtime.NumCPU()
@peterhellberg
peterhellberg / 40_primes.rb
Last active December 19, 2015 22:59
Fun with prime numbers…
require 'prime'
# Lets calculate some prime numbers
primes = 40.times.map { |n| n**2+n+41 } #=> 40 prime numbers (41, 43, 47, …, 1523, 1601)
# Let’s verify that they are in fact all prime numners
primes == primes.select(&:prime?) #=> true
@peterhellberg
peterhellberg / .gitconfig
Created July 19, 2013 08:40
A Git alias to display files with a lot of churn. (Inspired by @kytrinyx)
[alias]
churn = !git --no-pager log --name-only --oneline | grep -v ' ' | sort | uniq -c | sort -nr | head
@peterhellberg
peterhellberg / switch.lua
Created August 5, 2013 23:56
I just wrote, and _ran_ this little Lua script on my iPad using Codea.
function setup()
boolean("Skrivbordslampa", 1)
boolean("Hörnlampa", 2)
boolean("Sovrumslampa", 3)
end
function boolean(title, n)
parameter.boolean(title, false, function(b) lamp(n, b) end)
end
@peterhellberg
peterhellberg / smith.rb
Last active December 20, 2015 18:58
Monkeypatching Integer in order to find Smith numbers :)
require 'prime'
module Smith
def smith?
return false if self < 2 || self.prime?
sum_of_digits == sum_of_prime_factors
end
def sum_of_digits
to_s.split('').map(&:to_i).inject(:+)
@peterhellberg
peterhellberg / run_remote_code.lua
Created August 19, 2013 21:00
Run remote Lua scripts (from Codea) on your iPad.
function run_remote_code(url)
local eval_response = function(data, status, headers)
if (status == 200) then
code = string.gsub(data, '&quot;', "'")
loadstring(code)()
end
end
http.request(url, eval_response)
end
@peterhellberg
peterhellberg / screenshot.js
Created September 4, 2013 14:57
Site screenshots with the url-to-screenshot library (using PhantomJS)
var screenshot = require('url-to-screenshot');
var fs = require('fs');
var sys = require('sys')
var exec = require('child_process').exec;
if(process.argv[2]) {
var url = process.argv[2];
screenshot(url)
.width(800)
@peterhellberg
peterhellberg / alphabet.png
Last active December 24, 2015 10:19
Just playing around with the Graph gem.
alphabet.png
@peterhellberg
peterhellberg / acb-cylon.coffee
Last active December 29, 2015 04:09
Cylon robot with two LEDs and a Basic Force Sensing Resistor
fs = require('fs')
isUSBModem = (element) ->
element.match(/^cu.usbmodem\d+/)
device = fs.readdirSync('/dev').filter(isUSBModem)[0]
Cylon = require('cylon')
Cylon.robot
@peterhellberg
peterhellberg / audio_visualizer.pde
Last active December 29, 2015 07:09
Audio visualizer connected to an Arduino over Firmata
import cc.arduino.*;
import processing.serial.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
Arduino arduino;
AudioPlayer audio;
Minim minim;
FFT fft;