Skip to content

Instantly share code, notes, and snippets.

@finsterthecat
finsterthecat / gist:1176968
Last active January 16, 2018 21:01
Euler Problem #7 - 10001st prime number (much (20x!) faster - now break when primes > sqrt prime candidate)
primes = [2]
count = 1
prime_candidate = 2
start = Time.now()
until (count == 10001) do
prime_candidate +=1
while (true) do
psqrt = Math.sqrt(prime_candidate)
unless primes.
find do |prime|
@finsterthecat
finsterthecat / euler8.rb
Last active February 8, 2019 03:39
euler8: Find biggest product for 5 consecutive numbers
num = <<NUM
73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
@finsterthecat
finsterthecat / update-log.json
Created November 13, 2012 21:42
Update Log
{
"metadata" : {
"created" : "2013-10-17 13:45:20",
"author" : "Tony Brouwer"
},
"data" : {
[
{
"oen" : 123456,
"action" : "update",
package ca.ontario.moh.stix.loadfile;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Decrypt file using 7zip
*
*/
@finsterthecat
finsterthecat / fizzbuzz.rb
Created June 24, 2013 03:03
Now, am I hired or what?
1.upto(100).each do |x|
s = ""
s+= 'fizz' if (x % 3 == 0)
s += 'buzz' if (x % 5 == 0)
s = x.to_s if (s.empty?);
puts s
end
@finsterthecat
finsterthecat / gist:5867525
Created June 26, 2013 13:52
subl command for windows. Example of how to use doskey to creating a command without having to pollute my path.
doskey subl="C:\Program Files\Sublime Text 2\sublime_text.exe" $*
@finsterthecat
finsterthecat / i_failed_a_twitter_interview.rb
Last active January 16, 2018 20:59
Ruby solution for http://qandwhat.apps.runkite.com/i-failed-a-twitter-interview/. A bit more verbose but perhaps slightly more efficient solution than others? Nope, just more verbose.
walls = [2,5,1,2,3,4,7,7,6]
# array of max values of elements to the left for each element
def running_max(_walls)
maxmin = 0
_walls.inject([]) do |maxes, c|
maxes << if (c < maxmin) then
maxmin
else
maxmin = c
' Alt-F11 in Word to get into VBA mode
' Then Insert>>Module
' Paste this in and Run
Public Sub CreateOutline()
Dim docOutline As Word.Document
Dim docSource As Word.Document
Dim rng As Word.Range
Dim astrHeadings As Variant
@finsterthecat
finsterthecat / remove-all-containers.sh
Last active January 16, 2018 20:58
Remove all docker containers in one step
docker rm -vf $(docker ps -a -q)
buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}