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 / 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 / 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 / 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 / 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 / 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 / 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 / mod2powers.c
Created July 6, 2013 05:34
Messing around with a fun fact. Since unsigned integers wrap around, you are able to do modulo arithmetic implicitly for common sizes of 2^n, where n =128 (signed chars), 256 (unsigned chars), 65536 ( short int), and etc for long doubles and other types.
#include <stdio.h>
/*
Fun Fact:
Using an unsigned integer causes integer arithmetic module 2^n where n is the number of bits in the type
*/
main(){
unsigned char mod256;
mod256 = 16*18;
@EdgeCaseBerg
EdgeCaseBerg / wrap80.c
Created July 6, 2013 04:37
Exercise 1-22 from The C Programming Language by Brian W. Kernighan, Dennis M. Ritchie​ "Write a program to fold long input lines into two or more shorter lines after the last non-blank character that occurs before the n-th column of input. Make sure your program does something intelligent with very long lines, and if there are no blanks or tabs…
#include <stdio.h>
/*
Write a program to fold long input lines into two or more shorter lines after the last non-blank character that occurs before the n-th column of input. Make sure your program does something intelligent with very long lines, and if there are no blanks or tabs before the specified column.
*/
#define COLUMN_WIDTH 80
#define MAX_LINE 1000
@EdgeCaseBerg
EdgeCaseBerg / c_comment_removal.c
Created July 6, 2013 03:23
Exercise 1-23 from The C Programming Language by Brian W. Kernighan, Dennis M. Ritchie. Problem statement in gist. And yes, there is a goto in this code. This is an acceptable goto as a normal continue statement will not work due to the scope of the looping. If you still subscribe to religious dogmatism of the evils of a goto, then please refer …
#include <stdio.h>
/* Write a program to remove all comments from a C program,
Don't forget to handle quoted strings and character constants
properly. C Comments do not nest */
main(){
int first,second ,eatChar,lookAhead,previous;
first = getchar();
while((second = getchar()) != EOF){
@EdgeCaseBerg
EdgeCaseBerg / reverse.c
Last active September 7, 2018 17:14
Exercise 1-19 from The C Programming Language by Brian W. Kernighan, Dennis M. Ritchie​. "Write a function reverse(s) that reverses the character string s. Use it to write a program that reverses its input line by line" Only instead of a function I've written a small program that accepts piped in input and does it there
#include <stdio.h>
#define MAXLENGTH 1000
//Write a function reverse(s) that reverses the character string s. Use it to write a program that reverses its input line by line
void reverse(char s[], int lim){
int i,j;
j=lim-1;
i=0;