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 / classes-template.class.php
Created November 16, 2014 20:42
Example code for creating a flexible PHP template with shared header and footer behavior.
<?php
/*
Enables a PHP page to abstract out the site design (the template) from
the page design (the content).
Generally, a page will have a common header and footer (sidebars and the
like would live in one or the other). Following this pattern, a new page
can be created (after including the necessary files of course)) like so:
@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 / 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.
*
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 / 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.