Skip to content

Instantly share code, notes, and snippets.

@larryfox
larryfox / LICENSE.txt
Last active February 22, 2022 21:27
Determine if an elements background color is light or dark!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2015 Larry Fox <http://larryfox.us>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@larryfox
larryfox / readme.md
Last active December 20, 2015 09:49
Inlined images in notices, and embedded youtube videos in the Textual app.

Inlined images in notices, and embedded youtube videos in the Textual app.

Add it to your Styles scripts.js file.

Your User Styles can be found in ~/Library/Containers/com.codeux.irc.textual/Data/Library/Application Support/Textual IRC/Styles/. For more info see: http://www.codeux.com/textual/wiki/Styles.wiki

@larryfox
larryfox / algos.jl
Last active August 29, 2015 14:01
Merge sort problem sets in Julia and Ruby
halflength(array::Array) = (1+length(array))>>>1
take(array::Array, n::Int) = array[1:n]
drop(array::Array, n::Int) = array[n+1:end]
function sortcountinversions(array::Array{Int,1})
length(array) > 1 || return array, 0
n = halflength(array)
(left, x) = sortcountinversions(take(array, n))
(right, y) = sortcountinversions(drop(array, n))
@larryfox
larryfox / luhn.jl
Created May 21, 2014 13:40
Luhn algorithm in Julia
module Luhn
export luhn
function luhn(value::String)
a = reverse(split(value, ""))
s = 0
for i = 1:length(a)
n = parseint(a[i])
isodd(i) || (n *= 2)
@larryfox
larryfox / tumblr_2_siteleaf.rb
Created June 3, 2014 21:11
tumblr 2 siteleaf
#!/usr/bin/env ruby
require 'tumblr_client'
require 'siteleaf'
require 'sanitize'
require 'pry'
require 'json'
##
@larryfox
larryfox / min-heap.jl
Last active August 29, 2015 14:02
binary min heap in Julia
module Heap
export peek, min_insert!, extract_min!, build_min_heap!, decrease_key!
macro parent(i)
:($i>>1) # i/2
end
macro left(i)
:($i<<1) # 2i
require 'benchmark/ips'
require 'faker'
def extract_tld(email)
email.split('.'.freeze).last
end
emails = [].fill(0..1000) { Faker::Internet.email }
Benchmark.ips do |x|
@larryfox
larryfox / middleware.go
Last active August 29, 2015 14:03
Functional middleware chaining in Go
package middleware
import "net/http"
// Middleware are just functions that accept an
// http.Handler and return an http.Handler
type Middleware func(http.Handler) http.Handler
// Chain composes any number of middleware to another.
// Middleware(a).Chain(b, c)
function knapsack(v, w, capacity)
n = length(v) + 1
capacity += 1
A = zeros(Int, n, capacity)
for j in 1:capacity, i in 2:n
A[i,j] = if w[i-1] < j
max(
A[i-1, j],
A[i-1, j-w[i-1]] + v[i-1]
if isinteractive()
repl = Base.active_repl
repl.interface = Base.REPL.setup_interface(repl)
repl.interface.modes[1].first_prompt = \
repl.interface.modes[1].prompt = " \U2234 "
end