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 / wordlengthhisto.c
Last active March 13, 2023 20:20
Exercise 1-13 from The C Programming Language: by Brian W. Kernighan, Dennis M. Ritchie​ "Write a program to print a histogram of the lengths of words in its input. It is easy to draw the historgram with the bars horizontal; a vertical orientation is more challenging."
#include <stdio.h>
//In a word or not
#define IN 1
#define OUT 0
#define MAXLENGTH 100
// Write a program to print a histogram of the lengths of words in its input. It is easy to draw the historgram with the bars horizontal; a vertical orientation is more challenging.
main(){
//Maximum word length is 100, far more than neccesary
@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 / 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 / ActorTest.scala
Last active October 13, 2020 16:37
Basic Rate Limiting Actor implementation
package actors
import org.scalatest._
import org.scalatest.concurrent._
import org.scalatest.time.{ Millis, Seconds, Span }
import akka.actor.ActorSystem
import akka.util.Timeout
import java.util.concurrent.TimeUnit.MILLISECONDS
@EdgeCaseBerg
EdgeCaseBerg / SimpleLog.java
Created June 30, 2013 17:08
Simple singleton logging that creates logs directory wherever the process is run from. Just call SimpleLog.log( String message) ;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
//Seriously why do I have to import 3 things so get the date. Java = superflous objects everywhere
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public final class SimpleLog{
@EdgeCaseBerg
EdgeCaseBerg / GuiceThrowingProvidersExample.scala
Last active March 31, 2020 13:54
Example of using the ThrowingProviders and CheckedProviders in Guice. See full context: http://www.ethanjoachimeldridge.info/tech-blog/guice-scala-checked-providers
import com.google.inject.{AbstractModule, Provides, Guice}
import com.google.inject.throwingproviders.{ CheckedProvides, CheckedProvider, ThrowingProviderBinder }
import com.typesafe.config.{ ConfigException, ConfigFactory }
import java.net.{URL, MalformedURLException}
import javax.inject.Inject
import scala.collection.JavaConversions._
import scala.util.{Try, Success, Failure}
@EdgeCaseBerg
EdgeCaseBerg / TheCProgrammingLanguage_Exercise1_9.c
Last active May 28, 2019 15:54
Exercise 1-9 from The C Programming Language by Brian W. Kernighan, Dennis M. Ritchie​ "Write a program to copy its input to its output replacing each string of one or more blanks by a single blank"
#include <stdio.h>
main(){
int c;
while((c = getchar()) != EOF){
putchar(c);
if(c == ' '){
while((c = getchar()) == ' ')
;
putchar(c);
@EdgeCaseBerg
EdgeCaseBerg / WSClientBackend.scala
Last active October 16, 2018 20:01
WSClient powered backend for sttp.
package module
/* Don't import ._ because there's naming conflicts between sttp and ws for request bodies and whatnot */
import play.api.libs.ws
import ws.{ WSClient, WSClientConfig, WSRequest, WSResponse }
import play.api.libs.iteratee.Enumerator
import com.softwaremill.sttp._
import com.softwaremill.sttp.internal.SttpFile
import com.softwaremill.sttp.monadSyntax._
@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;
@EdgeCaseBerg
EdgeCaseBerg / makeZip.scala
Last active July 2, 2018 16:29
How to make a zip file in scala (Java 8)
import java.io.FileOutputStream
import java.nio.file.{Files, Paths, Path, FileVisitResult}
import java.nio.file.attribute.BasicFileAttributes
import java.nio.file.SimpleFileVisitor
def autoClosing[C <: Closeable, T](closeable: C)(c: C => T) = {
try {
c(closeable)
} finally {
closeable.close()