Skip to content

Instantly share code, notes, and snippets.

View EdgeCaseBerg's full-sized avatar
📉
Wondering why Github added statuses instead of something useful

Ethan Eldridge EdgeCaseBerg

📉
Wondering why Github added statuses instead of something useful
View GitHub Profile
@EdgeCaseBerg
EdgeCaseBerg / network_load.c
Last active December 29, 2015 23:39
Compile like: cc network_load.c -lm Run with ./a.out
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <math.h> /* link with -lm */
#define NETWORK_WIDTH 5
#define NETWORK_HEIGHT 4
#define NUMBER_NETWORKS 80
@EdgeCaseBerg
EdgeCaseBerg / interpolation.js
Created December 5, 2013 21:12
interpolation function for javascript. Converts strings like "{0}" to substituted values.
function interpolate(str){
/* Interpolate on {[0-9]+} */
if (arguments.length < 2)
return str;
/* Break string by it's interpolation parts */
var split = str.split(/\{([0-9]+)\}/gm);
var numex = /^\d+$/
for (var i = split.length - 1; i >= 0; i--) {
if(numex.test(split[i])){
@EdgeCaseBerg
EdgeCaseBerg / children.c
Last active December 30, 2015 10:09
Forking the process for each object in a population for multiple generations. Simple concept code.
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define GENERATIONS 4
#define POPULATION_SIZE 80
int main(){
@EdgeCaseBerg
EdgeCaseBerg / incremental_checkboxes.js
Created December 30, 2013 05:14
Simple javascript to ensure that checkboxes act in an incremental fashion. If checkbox 5 is clicked, then ALL checkboxes up to 5 will be checked, if checkbox 2 is unchecked, then all checkboxes after 2 will be unchecked as well.
<script type="text/javascript">
/* Javascript to force incremental changes
* If checkbox 1,2, 5 are checked then all
* migrations 1,2,3,4,5 should be applied.
* If checkbox 3 is unchecked, all checkboxes
* after 3 should be unchecked as well.
*/
var inputs = document.getElementsByName("migrations[]");
for (var i = inputs.length - 1; i >= 0; i--) {
inputs[i].onclick = function(evt){
@EdgeCaseBerg
EdgeCaseBerg / image_size.py
Last active January 12, 2021 09:52
Python function to read out size data for image types with no dependencies. Found originally at http://stackoverflow.com/questions/15800704/python-get-image-size-without-loading-image-into-memory and I added the ICO handler. (just ico not cursor files)
#-------------------------------------------------------------------------------
# Name: get_image_size
# Purpose: extract image dimensions given a file path using just
# core modules
#
# Author: Paulo Scardine (based on code from Emmanuel VAÏSSE), Ethan Eldridge (ICO)
#
# Created: 26/09/2013
# Copyright: (c) Paulo Scardine 2013
# Licence: MIT
@EdgeCaseBerg
EdgeCaseBerg / image-ref.py
Last active January 2, 2016 03:29
Finding Image References in source trees Recursive search for image filenames within a src tree Example Use: python image-ref.py -i /home/user/pictures -s /home/user/website/httpdocs
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
"""
Script to find image references
Authors
-------------------------------
- Ethan J. Eldridge [01/2014]
Looks through images directory to find list of files
@EdgeCaseBerg
EdgeCaseBerg / log_query.php
Last active September 14, 2016 21:00
Log SQL queries from WordPress
<?php
// in wordpress theme: functions.php add this in
function log_sql_queries($text_query){
/* //Uncomment me if you want a lot of info about where the sql query comes from and what action started it off
$traces = debug_backtrace();
$i = 0;
foreach ($traces as $tobj => $trace) {
if($trace['function'] == 'do_action'){
@EdgeCaseBerg
EdgeCaseBerg / 295evo.cpp
Created February 13, 2014 03:18
295 Evo Final. Code from several years ago
/*************************************************************************
* *
* Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
* All rights reserved. Email: [email protected] Web: www.q12.org *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of EITHER: *
* (1) The GNU Lesser General Public License as published by the Free *
* Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. The text of the GNU Lesser *
@EdgeCaseBerg
EdgeCaseBerg / reverse.c
Last active August 29, 2015 13:56
Reverse a forward linked list in Theta(N) time. (Note no checks on malloc because this is a toy program)
#include <stdio.h>
#include <stdlib.h>
struct node
{
struct node * next;
int seq;
};
@EdgeCaseBerg
EdgeCaseBerg / 60.go
Created May 13, 2014 12:29
http://tour.golang.org/#60 GoLang tutorial number 60
package main
import (
"fmt"
"net/http"
)
type String string
type Struct struct {