Skip to content

Instantly share code, notes, and snippets.

View zmalltalker's full-sized avatar

Marius Mathiesen zmalltalker

View GitHub Profile
@zmalltalker
zmalltalker / wordle.rb
Created January 11, 2022 08:52
Wordle CLI clone
def guess(guessed, correct)
guessed_chars = guessed.split(//)
correct_chars = correct.split(//)
used_chars = correct_chars.dup
result = guessed_chars.map.with_index do |c, idx|
if correct_chars[idx] == c
used_chars.delete(c)
:correct
elsif used_chars.include?(c)
#include <algorithm>
#include <cctype>
#include <fstream>
#include <iostream>
#include <list>
using namespace std;
string random_word(string path) {
ifstream file(path);
ifstream fileForRead(path);
require "#{File.dirname(__FILE__)}/../test_helper"
class CreateNewStoreTest < ActionController::IntegrationTest
def test_fail_to_manage_without_login
new_session do | tom |
tom.creates_new_store_and_activates_account
tom.logs_out
tom.attempts_to_manage_store_but_is_redirected_to_login
end
end
@zmalltalker
zmalltalker / README.org
Created July 20, 2012 08:55
Thinkpad fan control

Thinkpad fan control

My Thinkpad T400s kept shutting down when it was busy doing CPU intensive work. It turns out that the fan did not speed up to a high enough level to cool down the CPU, and I’d find messages in /var/log/messages stating that the CPU was dangerously hot.

Load the thinkpad_acpi module with manual fan control enabled

The first thing I did was to make it possible to manually control the fan speed. In order for this to work, the thinkpad_acpi kernel module needs to be loaded with a specific parameter. This can be

# coding: utf-8
class NorwegianBankAccount
# Pass me any kind of string representing an account number
def initialize(str)
@numbers = str.gsub(/[^\d]/,'')
end
# Prettified output
def to_s
begin
class NorwegianBankAccount
# Pass me any kind of string representing an account number
def initialize(str)
@numbers = str.gsub(/[^\d]/,'')
end
# Prettified output
def to_s
begin
parts = @numbers.split(//)
def place_text(text)
x = 130
y = 70
message = text.tr("abcdefghijklmnopqrstuvwxyz","nopqrstuvwxyzabcdefghijklm")
parts = message.scan(/.{16}/) #rot13
text_params = parts.map.with_index { |m, i|
y_pos = y + (i*10)
[i, x, y_pos]
"-fill orange -draw \"text #{x},#{y_pos} '#{m}'\""
@zmalltalker
zmalltalker / demo.rb
Created December 20, 2018 12:12
Callbacks, Ruby-style
q1 = Question.new("What is the color of my eyes?", "blue")
q1.ask do |answer|
answer.correct { puts "Nice!" }
answer.incorrect { puts "LOL" }
end
#!/bin/sh
msg=`date +"Klokka er %H %M %S"`
say -v Nora $msg
import math, sys
def utm_to_lat_lng(easting, northing, zone=32, northernHemisphere=True):
"""Converts from utm to lat_lng. Default zone is the one in which
Oslo and Akershus falls."""
if not northernHemisphere:
northing = 10000000 - northing
a = 6378137
e = 0.081819191
e1sq = 0.006739497