Skip to content

Instantly share code, notes, and snippets.

View larsbutler's full-sized avatar

Lars Butler larsbutler

  • Amazon Web Services, Inc.
  • Switzerland
View GitHub Profile
@larsbutler
larsbutler / fib.erl
Created March 25, 2017 15:35
Erlang - Recursive Fibonacci - Θ(n)
-module(fib).
fib(Term) ->
fib(Term, 1, 0).
fib(0, _Val, Prev) ->
Prev;
fib(1, Val, _Prev) ->
Val;
fib(Term, Val, Prev) ->
@larsbutler
larsbutler / gitconfig-git
Created October 18, 2016 17:41 — forked from stevenh512/gitconfig-git
URL rewriting in .gitconfig
# Use git and git+ssh instead of https
[url "git://github.com/"]
insteadOf = https://github.com/
[url "git@github.com:"]
pushInsteadOf = "git://github.com/"
[url "git@github.com:"]
pushInsteadOf = "https://github.com/"
@larsbutler
larsbutler / gu.py
Created July 21, 2016 09:33
Gunicorn experiment
# to run:
# gunicorn --workers=3 --worker-class sync gu:app
# gunicorn --workers=3 --worker-class gevent gu:app
# etc.
import threading
import os
def app(environ, start_response):
@larsbutler
larsbutler / Test.java
Last active August 15, 2022 10:31
Check CPU load on multiple cores in a multi-threaded Java process
import java.lang.management.ManagementFactory;
import com.sun.management.OperatingSystemMXBean;
public class Test {
public static void main(String [] args) {
// Probably this can vary, depending on whether you run from
// command line or from an IDE.
final int startingThreadCount = Thread.activeCount();
System.out.printf("Starting thread count: %d%n", startingThreadCount);
@larsbutler
larsbutler / ChatGUIMockup.java
Created June 8, 2016 21:05
ChatGUIMockup - Java 8 - Swing
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
@larsbutler
larsbutler / raw.md
Last active August 29, 2015 14:25
ZeroVM Networking Broker
  • Simple, modern networking broker
  • Built-in support to libzrt
  • http server
    • nginx
    • fastcgi
  • libzrt
  • 1 http frontend + 1 daemon backend
  • factor some object-query functionality into this
  • need good multiplexing file/stream transfer
  • no discovery needed
@larsbutler
larsbutler / ExampleTest.java
Last active November 27, 2015 23:03
Testable: super-lightweight unit testing lib for Java
/**
Copyright (c) 2015, Lars Butler
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@larsbutler
larsbutler / Vagrantfile
Last active August 29, 2015 14:23
Vagrantfile template
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
$script = <<SCRIPT
# TODO: Put your install script here.
SCRIPT
@larsbutler
larsbutler / RootishArrayStack.java
Last active August 29, 2015 14:22
CMSC 350 - Week2 discussion assignment
/**
* Most of the credit for this code goes to:
* http://opendatastructures.org/ods-java/2_Array_Based_Lists.html
* Code from opendatastructures.org is licensed under the Creative Commons
* License. See:
* - http://opendatastructures.org/
* - https://creativecommons.org/licenses/by/2.5/ca/
*
* I wanted to include a proper copyright notice, but opendatastructures.org
@larsbutler
larsbutler / README.txt
Created December 3, 2014 09:19
Vagrant dev environment example
1. Install Vagrant: http://www.vagrantup.com/downloads.html
2. Install VirtualBox: https://www.virtualbox.org/wiki/Downloads
3. Put Vagrantfile and vagrant-bootstrap.sh in some working directory
4. Open a shell, cd to that directory.
5. Run `vagrant up`. This will create the VM and run the vagrant-bootstrap.sh script
Other useful commands (run these from the same directory as the Vagrantfile)
- `vagrant halt`: shut down a machine
- `vagrant destroy -f`: destroy a machine; -f/--force is useful if the machine is running