Skip to content

Instantly share code, notes, and snippets.

Avatar

Mads Ohm Larsen omegahm

View GitHub Profile
View spongebobify.rb
require 'rspec'
RSpec.describe do
%w(spongebobify minisponge).each do |method|
context "##{method}" do
it 'fox' do
expect(send(method, 'fox')).to eq('fOx')
expect(send(method, 'FOX')).to eq('fOx')
end
@omegahm
omegahm / def.rb
Last active May 22, 2019
Time differences?
View def.rb
def run
t = 12.hours.from_now
n = Time.zone.now
puts t
puts n
puts (t.to_datetime - n.to_datetime)
puts (t.to_datetime - n.to_datetime).to_f
(t.to_datetime - n.to_datetime).ceil
end
@omegahm
omegahm / add_benchmark.rb
Created Dec 15, 2017
Benchmarking various array addition techniques with Ruby
View add_benchmark.rb
require "benchmark"
n = 100_000_000
puts "ADD"
puts "n = #{n}"
Benchmark.bm(20) do |measure|
measure.report("zip") do
output = ""
@omegahm
omegahm / ext-blas.py
Created Feb 21, 2017
Testing BLAS extension for Bohrium
View ext-blas.py
a = np.random.rand(2000, 3000).astype(np.float32)
b = np.random.rand(3000, 4000).astype(np.float32)
t0 = time()
c = np.dot(a, b)
t1 = time()
print "[Numpy] It took {}s".format(t1-t0)
print c
#print
@omegahm
omegahm / quasicrystal.py
Last active Nov 22, 2018
Quasicrystals in Python
View quasicrystal.py
# -*- coding: utf-8 -*-
import bohrium as np
from math import pi
import matplotlib.pyplot as plt
import matplotlib.colors as colors
fig = plt.figure()
plt.xticks([])
plt.yticks([])
View mandelbrot.py
# -*- coding: utf-8 -*-
import numpy as np
from sys import argv
from matplotlib import pyplot as plt
from matplotlib import colors
def mandelbrot(c, maxiter, h, log_log_h):
output = np.empty(c.shape, np.float64)
z = np.empty(c.shape, np.complex64)
az = np.zeros(c.shape, np.complex64)
View geckoboard.json
{
credits: {
enabled: false
},
chart: {
type: 'column',
backgroundColor: 'transparent'
},
title: {
View beep.js
var snd = new Audio("data:audio/wav;base64,//uQxAAAAAAAAAAAAAAAAAAAAAAASW5mbwAAAA8AAAAKAAASdAAZGRkZGRkZGRkZMzMzMzMzMzMzM0xMTExMTExMTExmZmZmZmZmZmZmgICAgICAgICAgJmZmZmZmZmZmZmzs7Ozs7Ozs7OzzMzMzMzMzMzMzObm5ubm5ubm5ub///////////8AAAA6TEFNRTMuOTIgAckAAAAAAAAAAAKAJAbAQQAAAAAAEfTbBHdkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//uQxAAAFd4u3zipgALHwaCrgpAAAAAAADCCAAAA8TgbPLEXgKAWefIB+VCKEA/w6QAIYAIQwX/4sYswdhEw6D/8MYCkAywMgBtiBzf//iNwBjijk4AoQXIKU///FKg2HD3wAjiZCdAbFjqGQ///8AZYpIOUBtuGJxkxcBibh8YN//////DBZPjljvDLYoMcYHJwAUBgCGESE6E0Oz/////////IuT4cQFpgFhkIJ3AOYVYxQEACxQRYAU4DCxHAACAFIAABEXIiABJ47Hosx/BuX3PcM2thv2SVkqKcznJGGsKto0hmydoUFkgXbco0gJ1dKHWrIMQIEUDS1LzhuwnF6ZiEm3F4JxZ16nhLwQZJ9ym1aUquUZSgko1K0lUNZHUeqoqI4G4323k7tV1fabnS9k91sGIXFbTrkrxpW
View ohm.js
function(doc) {
doc.postal_districts.forEach(function(pd) {
pd.postal_codes.forEach(function(pc) {
emit(pc.postal_code, {
postal_name: pc.name,
postal_code: pc.postal_code,
type: pc.type,
postal_district_id: pd.id,
slug: pd.slug
})
@omegahm
omegahm / check_methods.rb
Last active Aug 29, 2015
Find unused Ruby methods in current project
View check_methods.rb
skip_methods = %w(new create edit update destroy index show initialize to_s call as_json page per_page build up down change)
output = `grep -hir "^\s*def\s" *`
methods = output.split("\n")
puts "Found #{methods.size} methods."
ununsed_methods = []
methods.each_with_index do |line, i|
line = line.gsub(/^\s*/, '')
You can’t perform that action at this time.