Skip to content

Instantly share code, notes, and snippets.

😴
= (λx.x x)(λx.x x)

Nathan Lilienthal nixpulvis

😴
= (λx.x x)(λx.x x)
View GitHub Profile
View shell.rb
# Commands to be executed directly by this shell.
BUILTINS = {}
# The builtin `cd` for changing the shell's working directory.
BUILTINS['cd'] = lambda do |args|
# Change to the home directory by default.
args << ENV['HOME'] if args.empty?
# Read the destination path, doing very basic path expansion.
dest = args.pop.gsub(/~/, ENV['HOME'])
@nixpulvis
nixpulvis / fib
Last active Jun 26, 2018
Fibonacci (again)
View fib
#!/usr/bin/env elixir
defmodule Math do
def fibfast(n) do fib_acc(1, 0, n) end
def fib_acc(a, b, 0) do a + b end
def fib_acc(a, b, n) do fib_acc(b, a+b, n-1) end
def fibslow(0) do 1 end
def fibslow(1) do 1 end
def fibslow(n) do fibslow(n-1) + fibslow(n-2) end
View slack-one.colors
#282c34,#535A69,#abb2bf,#282c34,#535a69,#ABB2BF,#98c379,#e06c75
View server.rb
require "socket"
PORT = 1234
server = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM)
# NOTE: Commentting out this line will prevent multiple processes to run at
# once on the same port.
server.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEPORT, true)
server.bind(Addrinfo.tcp("", PORT))
@nixpulvis
nixpulvis / segv.c
Last active Mar 19, 2020
Intel pthreads Issue
View segv.c
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
static pthread_t thread;
static pthread_mutex_t mutex;
void* work(void* ptr)
{
pthread_detach(pthread_self());
@nixpulvis
nixpulvis / data.json
Created Sep 8, 2017
D3 Hierarchical Data
View data.json
{
"name": "Root Node",
"children": [
{ "name": "Child 1", "children": [] },
{ "name": "Child 2", "children": [
{ "name": "Child 3", "children": [] }
]}
]
}
@nixpulvis
nixpulvis / brainfuck-test.rs
Created May 29, 2017
Compare the speed of various BF implementations in Rust.
View brainfuck-test.rs
#![feature(test)]
extern crate test;
extern crate brainfuck;
extern crate bf;
use test::Bencher;
const HELLO_WORLD: &'static str = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]
>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.";
@nixpulvis
nixpulvis / seali.rb
Last active Dec 16, 2016
CLIs with subcommands that don't suck.
View seali.rb
# NOTE: This is a WIP, please pardon our dust.
#
# Example:
#
# git --namespace=foobar clone https://github.com/nixpulvis/seali
# #<Git @args=[], @flags={namespace: "foobar"}, @sub=#<Clone @args=["https://github.com/nixpulvis/seali"], @flags=[], @sub=nil>>
class Seali
class << self
attr_accessor :subs
@nixpulvis
nixpulvis / first_or_create.rb
Last active Jul 26, 2016
Retrying a first or create when two happen at the same time.
View first_or_create.rb
# Simple helper function for retrying a first or create when two happen
# at the same time and one violates the database unique index constraint.
def first_or_create(scope, attributes = {})
begin
scope.first_or_create(attributes)
rescue ActiveRecord::RecordNotUnique
retry
end
end
@nixpulvis
nixpulvis / debug_expr.rs
Created Apr 20, 2016
debug! an expression and it's syntax.
View debug_expr.rs
#[macro_export]
macro_rules! debug_expr {
($expr:expr) => {{
let value = $expr;
debug!("`{}` = {:?}", stringify!($expr), value);
value
}};
}
You can’t perform that action at this time.