Skip to content

Instantly share code, notes, and snippets.

View jonelf's full-sized avatar

Jonas Elfström jonelf

View GitHub Profile
@jonelf
jonelf / gist:639589
Last active September 29, 2020 09:32
Binary tree with some boundary rules
require 'rubygems'
require 'graphviz'
@min_level = 1
@max_level = 12
@max_depth = 10
start_level = 6
@g = GraphViz.new(:G, :type => "strict digraph" )
@jonelf
jonelf / fib.rb
Created April 29, 2020 12:59
Fibbooonnnnnaaaaaaaacccccccccccccccccccccccccccccccccciiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
n = 0; m = 1; puts "Fibonacci".split(//).map{|c| n, m = m, n + m; c * n}.join
@jonelf
jonelf / script.md
Last active September 24, 2019 11:46
Searching for and deleting a number of AWS CloudWatch Log Groups

If you ever want to delete a bunch of log groups:

$ aws --profile ProfileName logs describe-log-groups --output table | awk '{print $6}' | grep lambdaNamePrefix | sed -E "s/(.*)/aws --profile ProfileName logs delete-log-group --log-group-name \1/"

PS. This only returns a number of delete-log-group commands but does not execute them. DS.

@jonelf
jonelf / luhnTest
Last active July 2, 2019 10:23
Luhn test in Swift.
func lunhCheck(number : String) -> Bool
{
let reversed = reverse(number).map { String($0).toInt()! }
return reduce(enumerate(reversed), 0, {(sum, val) in
let odd = val.index % 2 == 1
return sum + (odd ? (val.element == 9 ? 9 : (val.element * 2) % 9) : val.element)
}) % 10 == 0
}
lunhCheck("49927398716")
@jonelf
jonelf / gist:2164553
Created March 22, 2012 21:04
Labouchère system simulation in Clojure
; A Clojure version of the Labouchère system simulation in
; CoffeeScript by Anders Löfgren that can be found at
; https://github.com/gnidde/gniddegit/blob/master/roulette.coffee
; Ruby version at https://gist.github.com/2127599
;
; I'm a complete beginner at Clojure so there's little to
; no chance that this code follows conventions and such.
; 2012-03-20 jonelf@gmail.com
(def table-zeros 1)
var xᅠ = 37;
var x = 41;
var ᅠx = 43;
if(xᅠ== 37 && x == 41 && ᅠx == 43) {
document.writeln("The truth is out there!")
} else {
document.writeln("<a href='https://goo.gl/yoX4Az'>WAT?</a>")
}
@jonelf
jonelf / x.js
Created September 28, 2018 14:11
x's in JavaScript
var p = (xᅠ, x, ᅠx) => console.log(xᅠ + ", " + x + ", " + ᅠx)
var xᅠ = 37;
p(xᅠ, x, ᅠx);
var x = 41;
p(xᅠ, x, ᅠx);
var ᅠx = 43;
p(xᅠ, x, ᅠx);
arr = "Pwzqemuözrözvykvvgt".split(//)
0.upto(28) {|n|
puts arr.map {|c| (c.ord - n).chr}.join
}
@jonelf
jonelf / gist:927782
Created April 19, 2011 13:44
Sudoku solver in CoffeScript based on the Python solution by Peter Norvig
# Sudoku solver in CoffeeScript based on the Python solution by Peter Norvig
# http://norvig.com/sudoku.html
# 2011-04-19 jonelf@gmail.com
#
# Throughout this program we have:
# r is a row, e.g. 'A'
# c is a column, e.g. '3'
# s is a square, e.g. 'A3'
# d is a digit, e.g. '9'
# u is a unit, e.g. ['A1','B1','C1','D1','E1','F1','G1','H1','I1']
@jonelf
jonelf / gist:5928868
Last active June 22, 2018 02:21
Math quiz
(0!+0!+0!)! = 6
(1+1+1)! = 6
2+2+2 = 6
3*3-3 = 6
√4+√4+√4 = 6
5/5+5 = 6
6-6+6 = 6
7-7/7 = 6
8-√√(8+8) = 6
√9*√9-√9 = 6