Skip to content

Instantly share code, notes, and snippets.

View blackfist's full-sized avatar

Kevin Thompson blackfist

View GitHub Profile
@blackfist
blackfist / painted_desert.nlogo
Created February 2, 2017 03:23
netlogo painted desert challenge
@blackfist
blackfist / termites_kevin.nlogo
Created February 2, 2017 03:21
netlogo termites picking up any color
@blackfist
blackfist / 1_explanation.md
Last active April 15, 2016 21:33
Elixir event handling -- am I failing at "let it crash?"

I have a genserver that is taking messages from a websocket and passing them to an event handler. The event handler receives a map from the genserver and takes action where appropriate. So for example, in response to a new user create event, the event handler would check if the user's email address comes from a suspicious domain, and if so, take some actions to reduce abuse.

So in event_handler.ex you can see that when a new message comes in for a user create event, I pass the message to UserHandler.handle_suspicious_domain. That function returns the same map which I pass to UserHandler.handle_suspicious_ip. But I'm not sure if that's idomatic since I'm not transforming the map, I'm just passing it from function to function.

Then you can see in user_handler.ex that I take the domain name through a set of transformations and then make a decision. Looking at line 25 you can see that I have a function that does nothing and only exists to prevent a crash. That seems wasteful and

@blackfist
blackfist / mailgun.ex
Last active April 3, 2018 14:00
Example of using Elixir and HTTPotion to send mail to Mailgun using the api.
defmodule Mailgun do
@doc """
Sends a basic message to an address. Expects a mailgun domain environment
variable (MAILGUN_DOMIAN) and a mailgun api key environment variable
(MAILGUN_API_KEY).
"""
@spec mail(String.t) :: String.t
def mail(toAddress) do
url = "https://api.mailgun.net/v3/#{System.get_env("MAILGUN_DOMAIN")}/messages"
headers = ["User-Agent": "Elixir",
Book.create(title: "I win", author: "U. Lose")
Book.create(title: "Robots", author: "Anne Droid")
Book.create(title: "Come on in", author: "Doris Open")
Book.create(title: "The Yellow River", author: "I. P. Freely")

New Years Resolutions for 2015

Mandarin Language resolutions

  • Acquire an additional 300 hours of practice, bringing my total to 900 hours.
  • End the year knowing at least 500 simplified characters
  • Finish reading one chinese novel (short)
  • Have at least 1 hour long conversation with an native speaker in each month of 2015

Keybase proof

I hereby claim:

  • I am blackfist on github.
  • I am kev (https://keybase.io/kev) on keybase.
  • I have a public key whose fingerprint is A1F2 5046 F79D B2C3 61F6 A9FB 1BF2 F63F BB73 1AFA

To claim this, I am signing this object:

@blackfist
blackfist / extraction.ipynb
Created December 15, 2014 16:19
Code to extract article text from VCDB
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@blackfist
blackfist / weird_sort.json
Created August 31, 2014 03:55
When I sort a data frame and plot it the values are properly sorted but the labels are not.
{
"metadata": {
"name": "",
"signature": "sha256:70ec5770cd4e35c7a408514277aa748a06612e2b2f4441a5efd73e02746d1a6b"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [