Skip to content

Instantly share code, notes, and snippets.

Jonas Elfström jonelf

Block or report user

Report or block jonelf

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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();
@jonelf
jonelf / rc4.rb
Last active Apr 29, 2016
Code golfing of the cipher RC4 in Ruby, 140 characters.
View rc4.rb
def e(k,t);s=*((j=q=w=0)..l=256);k*=l;(0..l).map{|i|j+=s[i]+k[i];s[i],s[j%=l]=s[j%=l],s[i]};(0...t.size).map{|i|q+=1;w=(w+s[q%=l])%l;s[q],s[w]=s[w],s[q];t[i]=t[i]^s[(s[q]+s[w])%l]};t;end
key = "test".chars.map(&:ord)
text = "test".chars.map(&:ord)
e(key, text) == [218, 234, 84, 101]
# e=->k,t{k*=l=256;j=q=w=0;s=*0..l;l.times{|i|j+=s[i]+k[i];s[i],s[j]=s[j%=l],s[i]};t.map{|c|w+=s[q+=1];s[q],s[w]=s[w%=l],s[q];c^s[(s[q]+s[w])%l]}}
e=->k,t{j=q=w=0;s=*0..l=256;l.times{|i|j+=s[i]+k[i];s[i],s[j]=s[j%=l],s[i]};t.map{|c|w+=s[q+=1];s[q],s[w]=s[w%=l],s[q];c^s[(s[q]+s[w])%l]}}
@jonelf
jonelf / random_fizzbuzz.rb
Last active Oct 3, 2017
A "random" FizzBuzz in Ruby. This is just for fun.
View random_fizzbuzz.rb
c = ('a'..'z').to_a
srand(1792579 * 1800)
f = (0..3).map { c[rand(26)] }
b = (0..3).map { c[rand(26)] }
a = [f, b].map {|s| s.join.capitalize }
srand(s = 93113 * 19243)
puts (0..99).map{|i| [a[0], a[0] + a[(srand(s) if i%15 < 1) || 1].to_s, a[1], i+1][rand(4)] }
You can’t perform that action at this time.