Skip to content

Instantly share code, notes, and snippets.

Marius Mathiesen zmalltalker

View GitHub Profile
View create_new_store_test.rb
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
View validate_bank_account.rb
# 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
View validate_bank_account.rb
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(//)
View rage.rb
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 Dec 20, 2018
Callbacks, Ruby-style
View demo.rb
q1 = Question.new("What is the color of my eyes?", "blue")
q1.ask do |answer|
answer.correct { puts "Nice!" }
answer.incorrect { puts "LOL" }
end
View froken-ur.txt
#!/bin/sh
msg=`date +"Klokka er %H %M %S"`
say -v Nora $msg
View utm.py
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
View table.html
<HTML>
<HEAD>
</HEAD>
<BODY>
<TABLE WIDTH="100%" HEIGHT="100%" STYLE="BACKGROUND-COLOR:BLUE">
<TR>
<TD VALIGN="MIDDLE" ALIGN="CENTER">
YO
</TD>
</TR>
View table.html
<html>
<head>
</head>
<body>
<table width="100%" height="100%" style="background-color:blue">
<tr>
<td valign="middle" align="center">
Yo
</td>
</tr>
@zmalltalker
zmalltalker / android.xml
Created Apr 26, 2017
SVG from Sketch to Android
View android.xml
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="31dp"
android:height="183dp"
android:viewportWidth="31"
android:viewportHeight="183">
<path
android:fillColor="#902e2e"
android:pathData="M0 0h31v183H0z " />
You can’t perform that action at this time.