Skip to content

Instantly share code, notes, and snippets.

View LOZORD's full-sized avatar
💭
i'm chillin

Leo Rudberg LOZORD

💭
i'm chillin
View GitHub Profile
@LOZORD
LOZORD / neg.rb
Created July 16, 2014 04:36
A Rigorous Sign Determining Algorithm For Real Rational Numbers
# implemented for all real rational numbers
class Float
# determine if a real rational number is zero
# we know a number is zero if one cannot divide another by it
def _is_zero_?
begin
# need to check for any non-zero number
# we might as well put pi in the cache
x = Math::PI.ceil
@LOZORD
LOZORD / progress_anim.js
Last active August 29, 2015 14:05
Since HTML <progress> bars don't have (non-pseudo) CSS attributes to animate for their width and inner color, I had to break out some nasty JS. Expect an actual library using just vanilla JS some time in the future...
/*
I used this tutorial below to get some nice looking bars to start out with:
http://css-tricks.com/html5-progress-element
Some page-specific code has been redacted, only the meat remains
Don't blame me if this doesn't compile! This meant for education!
*/
const IS_WEBKIT = 'WebkitAppearance' in document.documentElement.style;
const RGB_STR_REGEX = /^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/;
@LOZORD
LOZORD / i_believe.rb
Last active August 29, 2015 14:08
An explanation of my one-liner for MLH.
# A while back, Major League Hacking (mlh.io) wanted to make a video
# similar to the "I Believe That We Will Win" videos.
# In the video, hackers will say the line, showing off our passion and diversity.
# Being a hacker first, an a normal human second, I took the request as a challenge.
# When I remembered that `say` was a thing in Terminal, I knew what I had to do...
# In this gist (and hopefully a video), I'll explain what my one liner means.
# Hopefully, you'll learn some awesome Ruby tricks along the way.
# If you are new to Ruby, http://feministy.github.io/ruby_basics/#/ is a great start.
# Here's my one-liner:
@LOZORD
LOZORD / git_tutorial.markdown
Last active August 29, 2015 14:10
UPLVLS: git, GitHub, and you!
@LOZORD
LOZORD / qsort.hs
Last active August 29, 2015 14:12
A quicksort implementation in Haskell
-- the middle integer item from a list
middle :: [Integer] -> Integer
middle list = list !! (fromIntegral midInd)
where midInd = length list `div` 2
-- the median of three integer values
-- thanks to Tony Jiang from HH Coding for the improved algo!
qMed3 :: Integer -> Integer -> Integer -> Integer
qMed3 a b c = min firstMax (max firstMin c)
where firstMax = max a b
@LOZORD
LOZORD / ruby_tutorial.markdown
Last active August 29, 2015 14:21
UPLVLS: Learn to Program with Ruby!

UPLVLS: Learn to Program with Ruby!

Preceding slideshow here

Introduction

Go ahead and fire up a Ruby REPL. You can use irb if you want... Let's write the canonical first program, "Hello world!". In Ruby, it's very simple.

puts 'Hello world!'
@LOZORD
LOZORD / trunc_prime.hs
Last active August 29, 2015 14:22
Project Euler 37
import Data.List (nub, unfoldr)
-- FIXME
primeItr :: Integer -> Integer -> Bool
primeItr n i
| (i * i) > n = True
| otherwise = if (n `mod` i) == 0
then False
else primeItr n (i + 1)
isPrime :: Integer -> Bool
isPrime n = primeItr n 2 -- 2-7 primes do not count (n > 10)
@LOZORD
LOZORD / grid.java
Last active August 29, 2015 14:23
The Grid
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import java.lang.Math;
import java.lang.Number;
public class Grid
{
@LOZORD
LOZORD / powerset.hs
Created September 4, 2015 04:24
Powerset implementation in Haskell
import qualified Data.Set as Set
phi :: Set.Set a
phi = Set.empty
pset :: (Ord a) => Set.Set a -> Set.Set (Set.Set a)
pset set = if (Set.null set)
then Set.singleton phi
else
let head = Set.elemAt 0 set
@LOZORD
LOZORD / intro_to_haskell.markdown
Last active April 9, 2016 23:44
Introduction to Functional Programming with Haskell

Introduction to Functional Programming with Haskell

By Leo Rudberg, for the UPL Video Lecture Series

Preceding slideshow

Setup

First, let's make sure that you have ghc and ghci installed:

$ ghc --version && ghci
# ghci should boot up...