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 / 46.c
Last active December 19, 2015 10:29
Simple pseudo random algorithm from The C Programming Language Pg 46.
//This next variable could be declared in a seperate file if you wanted to. Not neccesary, its just a global
unsigned long int next;
int rand(void){
//extern because I like to be explicit about my constants
extern unsigned long int next;
next = next * 1103515245 + 12345;
return (unsigned int)(next/65536) % 32768;
}
@EdgeCaseBerg
EdgeCaseBerg / bits.c
Created July 7, 2013 22:40
Bit exercises from chapter two of The C Programming Language by Brian W. Kernighan, Dennis M. Ritchie​
#include <stdio.h>
#include <limits.h> //CHAR_BIT is defined in limits.h
/*Bit Shifting Exercises */
/* getbits: get n bits from position p*/
unsigned getbits(unsigned x, int p, int n){
return (x >> (p+1-n)) & ~(~0 << n);
/*Explanation:
(p+1-n) gets you the number of bits you'll have to shift off to move the n bits at position p to the rightmost position
@EdgeCaseBerg
EdgeCaseBerg / tribute.c
Created July 10, 2013 01:53
A tribute to Dennis Ritchie
#include <stdio.h>
char * chorus = "For he's a jolly good fellow";
char * ending = "Which no body can deny";
main(){
int i;
for(i=0; i < 3; ++i){
printf("%s\n",chorus);
sleep(1);
@EdgeCaseBerg
EdgeCaseBerg / background.sh
Created July 15, 2013 14:30
background cycler. Listen to system events (Such as screenshots, moving between workspaces, log on and log off) and change the background to a random one from an images directory. I've only used it on my system (Linux 3.2.0-23-generic #36-Ubuntu SMP x86_64 x86_64 x86_64 GNU/Linux -- Linux Mint 13 with maya) and I'm pretty sure it probably doesn'…
#!/bin/bash
#Script to change background image randomly when switching workspaces
#image directories:
dbus-monitor --profile "path='/org/mate/panel/applet/WindowListApplet/1'" |
while read -r msg; do
#echo $msg
@EdgeCaseBerg
EdgeCaseBerg / ListReference.java
Created July 17, 2013 14:53
Demonstration that objects within a list are passed by reference to any other list they're appended to. In other words: List 1 = [ Object1, Object2, Object3 ... ObjectN ] List 2 = [] List 2 .add ( some object from List 1 ) List 2 will have a reference to the same object in List 1.
import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
public class ListReference{
public static int id = 0;
protected static class MyLittleObject{
public int val;
public MyLittleObject(){this.val=ListReference.id; ListReference.id +=1; }
@EdgeCaseBerg
EdgeCaseBerg / serve.py
Created July 26, 2013 02:04
Simple xemark serving server. Using the xemark executable from the my xemark repository as a cgi for input. Serves only one file.
from wsgiref.util import setup_testing_defaults
from wsgiref.simple_server import make_server
import os
def callXemark():
return os.popen("./xemark < example.xe").read()
def xemarkapp(environ, start_response):
status = '200 OK'
@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):
@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 / 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 / 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.
"""