Skip to content

Instantly share code, notes, and snippets.

@blinsay
blinsay / README.md
Last active June 14, 2020 13:30
Randomized Contour Lines

Randomly placed actors explore a 2d function by walking along contour lines. Perlin noise courtesy of d2fn.

(lldb) bt all
thread #1, queue = 'com.apple.main-thread'
frame #0: 0x00000001001fbdb5 blep`core::sync::atomic::atomic_load::h6aee38d0824dc7a5(dst=0x0000000100a05d80, order=Relaxed) at atomic.rs:2276:51
frame #1: 0x00000001000095ed blep`core::sync::atomic::AtomicUsize::load::hb7a33ef6938f2383(self=0x0000000100a05d80, order=Relaxed) at atomic.rs:1364:29
frame #2: 0x000000010000cd3a blep`blep::main::h521b6e1d650d0853 at main.rs:55:10
frame #3: 0x0000000100018bc2 blep`std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::hbeabee956eb51f15 at rt.rs:67:33
frame #4: 0x0000000100216118 blep`std::panicking::try::do_call::hf2b35caddf59127c [inlined] std::rt::lang_start_internal::_$u7b$$u7b$closure$u7d$$u7d$::hd38dd0e12f275c20 at rt.rs:52:12 [opt]
frame #5: 0x000000010021610c blep`std::panicking::try::do_call::hf2b35caddf59127c at panicking.rs:305 [opt]
frame #6: 0x000000010021925b blep`__rust_maybe_catch_panic at lib.rs:86:7 [opt]
(lldb) run
Process 15007 launched: '/Users/benl/src/blep/target/debug/blep' (x86_64)
starting thread ThreadId(2)
starting thread ThreadId(4)
starting thread ThreadId(3)
starting thread ThreadId(5)
200 202ms
200 205ms
200 201ms
200 207ms
use rand::{thread_rng, Rng};
use std::convert::TryFrom;
fn main() {
loop {
print!("{}", char::try_from(0x2571 + (thread_rng().gen_bool(0.5) as u32)).unwrap());
}
}

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

@blinsay
blinsay / euler5.clj
Last active December 22, 2015 19:39
(defmacro divides?
"Return true if y divides x. Expands to (= 0 (mod x y))"
[x y]
`(zero? (mod ~x ~y)))
(defn prime?
"Check to see if a number is prime. Naive"
[n]
(let [r (inc (Math/floor (Math/sqrt n)))]
(nil? (some #(divides? n %) (range 2 r)))))
/*
Soooo, I have a POJO with an Optional<T> field that *isn't set by default*. When the field isn't included in
a JSON document, I'd like that field to be deserialized as Optional.absent() rather than 'null'. Just doing
the default thing (below) I end up having the Optional<T> field being set to null after deserialization.
I suspect that Jackson is being smart and just not setting fields that aren't in the JSON. Is there something
I can do to make sure it initalizes all the fields, or is the Right Thing To Do just to give my Optional<T>
field a default value?
func Create(bot *core.Gobot) {
// matches is actually a map[string]string
matches, found := bot.Config.Plugins["matcher"]["matches"]
if !found {
log.Printf("Can't find matcher/matches plugin conf. Plugin will not run.")
return
}
switch matches := matches.(type) {
case map[string]interface{}:
@blinsay
blinsay / goenv.sh
Last active December 16, 2015 04:29
#!/bin/bash
# Apparently this doesn't work. :((((((((((((
_path_remove () { export PATH=`echo -n $PATH | awk -v RS=: -v ORS=: '$0 != "'$1'"' | sed 's/:$//'`; }
goenv() {
new_env=${1:-`pwd`}
old_env=$GOPATH
if [[ -z $old_env ]]; then
#!/usr/bin/env python
# encoding: utf-8
from eventlet import patcher, GreenPool
patcher.monkey_patch(all = True)
import sys
from eventlet.queue import Queue, Empty
from boto import connect_s3