Skip to content

Instantly share code, notes, and snippets.

@skatenerd
skatenerd / splat.rb
Last active September 3, 2020 13:18
splat confusion
irb(main):014:0> def low(a,b)
irb(main):015:1> a+b
irb(main):016:1> end
=> :low
irb(main):017:0> def high(*args, **kwargs)
irb(main):018:1> low(*args, **kwargs)
irb(main):019:1> end
=> :high
irb(main):020:0> high(1,2)
=> 3
class Base
A_VALUE = 2
def foo
raise "NOT IMPLEMENTED"
end
end
class Sub < Base
def foo
@skatenerd
skatenerd / gotcha.rb
Created March 4, 2020 20:50
ruby gotcha
# We all know about this Python gotcha:
# def foo(x=[]):
# x.append(1)
# return len(x)
# But the answer is not to do what ruby does.
# Would you expect this to run quickly or slowly?
def runonce
urls = ["yahoo.com", "google.com", "bing.com", "marxists.org"]
@skatenerd
skatenerd / join_test.py
Last active October 16, 2018 19:37
peewe join
import os
from peewee import CharField, DecimalField, IntegerField, FloatField, DateTimeField, BooleanField, TextField, CompositeKey, DateField, Model, ForeignKeyField
from playhouse.postgres_ext import JSONField, PostgresqlExtDatabase
# Add real values here...
database = PostgresqlExtDatabase()
class BaseModel(Model):
class Meta:
@skatenerd
skatenerd / expand.hs
Created March 21, 2018 23:34
expand.hs
simple = do
first <- pop
pop
return first
pop >>= (\first -> (pop >>= (\_ -> return first)))
@skatenerd
skatenerd / keybase.md
Created January 23, 2018 16:11
keybase

Keybase proof

I hereby claim:

  • I am skatenerd on github.
  • I am skatenerd (https://keybase.io/skatenerd) on keybase.
  • I have a public key ASDrPaKbWuXS650wdiXEXgtej4fVbFwi8oSMyTHGyDvKAQo

To claim this, I am signing this object:

bad = ->
l = []
for blob in blobs
l.push(blob)
go()
go = ->
blob = l.pop()
$.get('www.google.com/' + blob).success ->
cosole.log("I just requested to: " + blob)
@skatenerd
skatenerd / comparer.hs
Last active March 23, 2017 01:03
hand comparer
{-# LANGUAGE ScopedTypeVariables #-}
module Lib where
import Data.List
import Data.Maybe
import Safe
import Debug.Trace
import Data.Function
data Suit = Hearts | Clubs | Spades | Diamonds deriving (Eq, Show, Ord)
@skatenerd
skatenerd / lib.hs
Created February 10, 2017 21:31
factorization
module Lib (factor, intLog) where
import Data.Map
import Debug.Trace
divides bottom top = (mod top bottom) == 0
intDivide bottom top = fst $ divMod top bottom
intLog base total = go base total 0
where go base total count = if (divides base total)
@skatenerd
skatenerd / electoralvotes.py
Last active November 14, 2016 16:28
whose votes are worth more?
def weighted_average(categories):
total_weight = sum(weight for (weight,_) in categories)
sum_of_products = sum(weight * value for (weight, value) in categories)
return sum_of_products / total_weight
swing_states = {
'colorado': 9,
'florida': 29,
'iowa': 6,
'michigan': 16,