Skip to content

Instantly share code, notes, and snippets.

View kbob's full-sized avatar

Bob Miller kbob

  • Eugene, Oregon, USA
View GitHub Profile
# 12 MHz clock
set_io -nowarn CLK 35
# RS232
set_io -nowarn RX 6
set_io -nowarn TX 9
# LEDs and Button
set_io -nowarn BTN_N 10
set_io -nowarn LEDR_N 11
@kbob
kbob / gist:3134a65680dd3e0e0015ed7ad423824d
Created November 18, 2018 13:49
Trying to instantiate a 2F PLL -- doesn't work.
`default_nettype none
`define W 24
module top (
input CLK,
output LED1,
output LED2,
output LED3,
output LED4,
// BEGIN kbob
// This is identical to https://vulkan-tutorial.com/Drawing_a_triangle/Swap_chain_recreation
// as of 2018-06-13 except for code between the "BEGIN kbob" and "END kbob" comments.
// The original code is still there but commented out with "//-".
//
// Built with MoltenVK 1.1.73 and GLFW 20180519 for MacOS, the original never recreated
// the swap chain. It continued to draw at the original 800 by 600 resolution and scaled
// the result to fit the resized window.
//
// Also, according to GLFW doc, the glfwGetWindowSize() is not the right function to call.
@kbob
kbob / dda2.c
Created November 2, 2016 17:00
Anti-aliasing, subpixel-positioned left edge DDA.
#define EXPECT
#include <assert.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
@kbob
kbob / print_nine_digit_positive.c
Created June 10, 2016 20:22
Silly unrolled print function
#include <assert.h>
#include <stdint.h>
#include <unistd.h>
/* print nine digit positive */
char *p9dp(uint32_t n, char *p)
{
uint32_t a = n % 10;
n /= 10;
if (n) {
@kbob
kbob / main.rs
Created February 20, 2016 21:53
Trie insertion and query
struct TrieNode {
is_terminal: bool,
children: [Option<Box<TrieNode>>; 256],
}
impl TrieNode {
fn new() -> TrieNode {
let mem : TrieNode = unsafe { std::mem::zeroed() };
mem
}
@kbob
kbob / infinite_combinations.py
Created December 23, 2012 18:16
Iterate combinations of an infinite set
import itertools
def infinite_combinations(n, iterator):
seen = []
for item in iterator:
for subset in itertools.combinations(seen, n - 1):
yield subset + (item,)
seen.append(item)
@kbob
kbob / Ramanujan_number.py
Created December 23, 2012 16:43
Find Ramanujan's number.
#!/usr/bin/python
from itertools import count
def ramanujan_number():
cubes = (i**3 for i in count(1))
smaller_cubes = []
sums = {}
for n in cubes:
for m in smaller_cubes:
@kbob
kbob / nonrepeating_digits.py
Last active December 10, 2015 01:18
https://plus.google.com/u/0/114070220225686847236/posts/d7xrq9ph7WJ There are no repeated digits, and no adjacent digits with a difference of one, in the number 13524. How many such arrangements of 5 digits are there? What's the shortest program you can write to find out?
#!/usr/bin/python
# https://plus.google.com/u/0/114070220225686847236/posts/d7xrq9ph7WJ
# There are no repeated digits, and no adjacent digits with a
# difference of one, in the number 13524. How many such arrangements
# of 5 digits are there? What's the shortest program you can write to
# find out?
import itertools
@kbob
kbob / fizzbuzz.py
Created November 22, 2012 23:36
FizzBuzz
#!/usr/bin/python
from itertools import count, cycle, islice, izip, repeat
def fizzbuzz(n):
class d(int): __add__ = lambda self, other: other
def i(x): return x
def f(x): return x + 'Fizz'
def b(x): return x + 'Buzz'
def p(x): print x