Skip to content

Instantly share code, notes, and snippets.

View dimo414's full-sized avatar
🦀
Playing with Rust

Michael Diamond dimo414

🦀
Playing with Rust
View GitHub Profile
@dimo414
dimo414 / bprefix.py
Created June 24, 2012 02:09
Testing Prefix Lookup Data Structures
import bisect
import error;
class Prefix:
'''
A prefix data structure built on a sorted list, which uses binary search.
Note that for more reasonable lookup, it only searches in lower
case. This means there can be colliding strings such as 'prefix' vs 'Prefix'.
In this case, more recent inserts override older ones.
import java.io.*;
import java.util.*;
import com.google.common.collect.*;
public class WordFreq {
public static void main(String[] args) throws FileNotFoundException {
final HashMultiset<String> counts = HashMultiset.create(
ImmutableList.copyOf(new Scanner(new File(args[0]))));
@dimo414
dimo414 / includes-common.inc.php
Last active November 11, 2016 19:28
Sample PHP website structure, demonstrating environment abstraction
<?php
/*
This file handles all necessary setup that has to happen on each page load.
It should have no need to be aware of where the server is running from.
*/
session_start();
// This file isn't tracked by version control, and might not exist
@dimo414
dimo414 / cat.py
Created June 26, 2012 04:54
Fast File Concatenation in Python
'''
Tests different methods of concatenating files in Python.
'''
from __future__ import print_function
import json,os,shutil,subprocess
import util
def verify(file,expected):
count = 0
@dimo414
dimo414 / index.php
Created April 29, 2013 21:19
How To Identify The Requested Page In PHP
<code><pre>
<?php
echo "__FILE__: ".__FILE__."\n";
echo "PHP_SELF: ".$_SERVER['PHP_SELF']."\n";
echo "SCRIPT_NAME: ".$_SERVER['SCRIPT_NAME']."\n";
echo "REQUEST_URI: ".$_SERVER['REQUEST_URI']."\n";
echo "parse_url(REQUEST_URI): ".parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH)."\n";
?>
@dimo414
dimo414 / description.md
Created March 4, 2020 06:06
St. Petersburg Paradox Simulation

The St. Petersburg paradox, in a nutshell, is: why would you refuse to play a game with an unlimited expected payout? Shouldn't you be willing to pay any finite price to play, since your expected return is infinite?

This simulation explores what the Stanford Encyclopedia refers to as the "Average Win" explanation, that:

Expected value is in effect average payback in the long run.... [I]f you're going to play St. Petersburg with a substantial fee per game, you're likely to have to play a very very long time before you come out with a positive net payoff. Ordinary practical considerations thus apply... You may have to play a very long time before winning once. But worse: in a series of losses, the amount needed for the next bet rises. How much bankroll would you need to guarantee success...? Whatever bankroll you take into the casino, there's a chance that this will not be enough.

The

@dimo414
dimo414 / MapSpeedTest.java
Created March 4, 2020 06:22
Benchmark of map implementation access speeds
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
@dimo414
dimo414 / build.md
Last active April 30, 2020 07:04
Run Slack Dogebot on Raspberry Pi

Build the Luit/dogebot binary (I prefer to do so in a Docker container) for ARM:

$ docker run -v /tmp:/mnt/tmp -it debian:testing
docker$ apt-get update && apt-get install -y git golang
# Ensure build dependencies are available locally
docker$ go get github.com/Luit/dogebot/src/dogebot
docker$ git clone https://github.com/Luit/dogebot
docker$ cd dogebot/src/dogebot
# Build a Raspberry Pi binary
@dimo414
dimo414 / GCChurn.java
Created March 26, 2013 04:34
GC Churn Java application, intended to cause high amounts of garbage collection for benchmarking
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Runnable which causes a heavy yet stable amount of GC; useful for
* benchmarking applications under load.
*
@dimo414
dimo414 / health-plex.sh
Last active April 3, 2021 18:42
Plex Healthcheck
#!/bin/bash
# Checks that a Plex server is up. For devices on a local network your
# router may have created [hostname].local or [hostname].lan DNS entries;
# otherwise you can pass an IP address or ensure your server is remotely
# accessible (https://support.plex.tv/articles/200931138/).
#
# See also
# https://old.reddit.com/r/PleX/comments/7qolre/what_do_others_do_to_monitor_plex_health/
# https://support.plex.tv/articles/201638786-plex-media-server-url-commands/
#