Skip to content

Instantly share code, notes, and snippets.

@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
# 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
<HTML>
<HEAD>
</HEAD>
<BODY>
<TABLE WIDTH="100%" HEIGHT="100%" STYLE="BACKGROUND-COLOR:BLUE">
<TR>
<TD VALIGN="MIDDLE" ALIGN="CENTER">
YO
</TD>
</TR>