Skip to content

Instantly share code, notes, and snippets.

@finsterthecat
finsterthecat / sql-batch.sql
Created November 17, 2010 15:53
Driver script to run a series of scripts (sql, sqlldr or otherwise) within oracle sqlplus
-- cross platform! Works on unix and windows. Notice ability to run host programs?!
accept _usr prompt 'UserName: (app) ' default 'app'
accept _pwd prompt 'Password: (&_usr) ' default &_usr hide
accept _tns prompt 'TNSalias: (SUE2DEV) ' default 'SUE2DEV'
whenever sqlerror exit
connect &_usr/&_pwd@&_tns
whenever sqlerror continue
@finsterthecat
finsterthecat / drop_all.sql
Created January 25, 2011 23:01
Oracle script: Drop everything for your user. Handy when you can't just delete your user.
declare
stringa varchar2(100);
cursor cur is
select *
from user_objects;
begin
for c in cur loop
begin
@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 / 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)
@finsterthecat
finsterthecat / google_interview.rb
Last active February 9, 2021 06:23
Solves the problem that is the basis of the example Google Interview here: https://www.youtube.com/watch?v=XKu_SEDAykw
#
# Google interview question: find all combinations that sum up to a value
#
require 'set'
def summables(vector, remainder, so_far)
return Set.new if remainder < 0 #did not find a sum
return [so_far].to_set if remainder == 0 #found a sum
car = vector[0]