Skip to content

Instantly share code, notes, and snippets.

DoggettCK / fibonacci_stream_resource.ex
Last active Sep 25, 2019
1_000_000th Fibonacci number using Elixir Stream.resource/3
View fibonacci_stream_resource.ex
iex(1)> fib = Stream.resource(fn -> {1, 1} end, fn {a, b} -> {[a], {b, a + b}} end, fn _ -> nil end)
#Function<55.117072283/2 in Stream.resource/3>
iex(2)> fib |> Stream.drop(1_000_000) |> Enum.take(1) |> hd
DoggettCK / password_generator.ex
Last active Sep 25, 2019
Password generation with macros in Elixir
View password_generator.ex
defmodule ChooseFrom do
defmacro __using__(options) do, fn {name, alphabet} ->
function_name = :"choose_#{name}"
chars = String.graphemes(alphabet)
build_alphabet(name, function_name, chars)
end) ++ [
quote do
defp generate_minimums(chars, _options), do: chars
DoggettCK /
Created Sep 6, 2019
OpenCV Python script to put the Matrix falling letters behind Taylor Swift for trueheart78
#!/usr/bin/env python
import os
import sys
import numpy as np
import cv2
FRAME_DELAY = int(sys.argv[1]) if len(sys.argv) > 1 else 30
foreground = cv2.VideoCapture('glowy_eyes.gif')
background = cv2.VideoCapture('matrix.gif')
DoggettCK / .vimrc
Created Jun 27, 2018
New .vimrc until I get it in the main project
View .vimrc
set nocompatible
syntax on
filetype plugin indent on
" Open splits to the bottom/right
set splitright
set splitbelow
" Package management
packadd minpac
call minpac#init()
DoggettCK / quick_sell.js
Created Apr 3, 2018
Auto-click Steam card inventory to quick-sell
View quick_sell.js
// Requires Enhanced Steam Chrome Plugin
// Clicks Nth item (after skipping unsellable coupons/gems/etc...), causing ES to pop up Quick/Instant sell buttons
// Clicks on next item after ms_til_next milliseconds
function clickQuickSell(items_to_skip, ms_til_next) {
jQuery("div.item:not(.btn_disabled) a.inventory_item_link").eq(items_to_skip).click();
setTimeout(function() {
clickQuickSell(items_to_skip, ms_til_next);
}, ms_til_next);
View time_utils.ex
defmodule TimeUtils do
@ms_filetime_offset 116444736000000000
def filetime_to_unix(filetime) do
div(filetime - @ms_filetime_offset, 10000)
def unix_to_filetime(datetime) do
@ms_filetime_offset + (datetime * 10000)
DoggettCK / base_n.exs
Last active Aug 25, 2016
Generates encode and decode methods for base 2->62
View base_n.exs
for {base, name} <- (2..62 |>{&1, "Base#{&1}" |> String.to_atom}))) do
# NOTE: Modules will be named :Base2, :Base3, ..., :Base62
defmodule name do
@moduledoc """
Automatically generated #{name} encode/decode functions
@base base
@alphabet [?0..?9, ?a..?z, ?A..?Z]
|> Enum.flat_map(fn x -> x end)
|> to_string
DoggettCK / pdf_grammar.ex
Created May 11, 2016
Preliminary Neotomex PDF object grammar. Still has some bugs around object name edge cases.
View pdf_grammar.ex
defmodule PdfObjectGrammar do
use Neotomex.ExGrammar
defp describe_object(o, prefix) do
IO.puts "#{prefix} received"
IO.inspect o
@root true
define :object, "bool / numeric_object / string_object / name / array / dictionary"
DoggettCK /
Created Feb 12, 2013
Creates DDL from generated Elixir Models
from inspect import getmembers, isclass
from sqlalchemy.schema import CreateTable
from elixir import metadata, setup_all, Entity, EntityMeta
from sys import modules
def generate_ddl(module, tablenames=[]):
prev_bind = metadata.bind
metadata.bind = "sqlite://"
from bitarray import bitarray
import mmh3
from math import log, pow, ceil
class BloomFilter:
def __init__(self, size, hash_count):
self.size = size
self.hash_count = hash_count
self.bit_array = bitarray(size)