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 EdgeCaseBerg

📉
Wondering why Github added statuses instead of something useful
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / wp_json.py
Created November 20, 2013 21:13
Pull WordPress posts and their meta data out into JSON for migration to Harp
"""
Author: Ethan Joachim Eldridge
Website: ejehardenberg.github.io
Contact me through my github.
This code is available for use in the public domain to help out with
people migrating from WP to Harp, http://harpjs.com/
I do appreciate a star on the gist if it helped you though.
"""
@EdgeCaseBerg
EdgeCaseBerg / querystringparse.c
Last active December 25, 2015 01:29
A URL string parsing function in C.
/*
Needs strmap http://pokristensson.com/strmap.html
*/
/*
* Parse the url and store values into the hash table
* returns the number of values successfully placed into the hashtable
*/
int parseURL(char * url, int urlLength, StrMap * table){
int i;
int j;
@EdgeCaseBerg
EdgeCaseBerg / coinProb.py
Created September 11, 2013 00:09
Imperical Analysis for Stephanie
1 tails = 0
2 heads = 0
3 success = 0
4 numTrials = 10000000
5
6 import random
7
8
9 for t in range(numTrials):
10 for i in range(256):
@EdgeCaseBerg
EdgeCaseBerg / orm.py
Last active December 21, 2015 02:19
ORM for mysql and python. Subclass ORM_Base with a camel cased class name of your table name and bam. Create a subclassed object, passing in the primary key as the parameter. Kapow. You now have a copy of the object that was in the database.
MYSQL_HOST="localhost"
MYSQL_USER="username"
MYSQL_PASS="password"
MYSQL_DB ="databasename"
#Query for getting column names from database
TABLE_INFO = "SELECT distinct column_name FROM information_schema.columns WHERE table_name = '%s' order by ordinal_position asc"
class ORM_Base():
def __init__(self,pk_id=None):