Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonas Elfström jonelf

View GitHub Profile
@jonelf
jonelf / fib.rb
Created Apr 29, 2020
Fibbooonnnnnaaaaaaaacccccccccccccccccccccccccccccccccciiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
View fib.rb
n = 0; m = 1; puts "Fibonacci".split(//).map{|c| n, m = m, n + m; c * n}.join
@jonelf
jonelf / script.md
Last active Sep 24, 2019
Searching for and deleting a number of AWS CloudWatch Log Groups
View script.md

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.

View fra.rb
arr = "Pwzqemuözrözvykvvgt".split(//)
0.upto(28) {|n|
puts arr.map {|c| (c.ord - n).chr}.join
}
@jonelf
jonelf / x.js
Created Sep 28, 2018
x's in JavaScript
View x.js
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);
View The X-variables.js
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>")
}
View gist:4db13fd3ae1dff2895dcd7db51e13a54
ruby -e "32.times{|l|puts (0..78).map{|n|x=y=i=0;(x,y,i=x*x-y*y+n/38.0-1.5,2*x*y+l/14.0-1,i+1)until(x*x+y*y>4||i>78);(32+i).chr}*''}"
View regex.java
"jonas.elfstrom+connect@e-man.se".replaceAll("(.*)([+].*)(@.*)","$1$2");
View roulette.rb
prng = Random.new
Trials = 37000
lost = 0
Trials.times do
bad_results = 0
250.times do
result = prng.rand(1..37)
if result <= 19
bad_results += 1
else
@jonelf
jonelf / dodips.rb
Created Sep 24, 2015
Number of IPs owned by DoD
View dodips.rb
require 'ipaddr'
sum = 0
File.open("us-military-dod.csv").each_line do |line|
ip1, ip2 = line.split(/;/)
sum += IPAddr.new(ip2).to_i - IPAddr.new(ip1).to_i
end
puts sum
@jonelf
jonelf / weeknumbers.java
Last active Sep 15, 2015
Week numbers are hard.
View weeknumbers.java
// Week numbers are hard. Here's a bug I found earlier today.
// If you want to construct a string like this
String yearWeekKey = year + week;
// then you can't use
String year = new SimpleDateFormat("yyyy").format(date);
String week = String.format("%02d", new LocalDate(date).getWeekOfWeekyear());
// when date is 2016-01-01 because the key will be "201653" and that week does not exist.
// Instead you have to use .weekyear() because that correctly returns 2015 for 2016-01-01.
String year = new DateTime(ets).weekyear().getAsString();
You can’t perform that action at this time.