Skip to content

Instantly share code, notes, and snippets.

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 / image_size.py
Last active Jan 12, 2021
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)
View image_size.py
#-------------------------------------------------------------------------------
# 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 Oct 13, 2020
Basic Rate Limiting Actor implementation
View ActorTest.scala
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 Jun 30, 2013
Simple singleton logging that creates logs directory wherever the process is run from. Just call SimpleLog.log( String message) ;
View SimpleLog.java
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 Mar 31, 2020
Example of using the ThrowingProviders and CheckedProviders in Guice. See full context: http://www.ethanjoachimeldridge.info/tech-blog/guice-scala-checked-providers
View GuiceThrowingProvidersExample.scala
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
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"
View TheCProgrammingLanguage_Exercise1_9.c
#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 Oct 16, 2018
WSClient powered backend for sttp.
View WSClientBackend.scala
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 Sep 7, 2018
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
View reverse.c
#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 Jul 2, 2018
How to make a zip file in scala (Java 8)
View makeZip.scala
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()
@EdgeCaseBerg
EdgeCaseBerg / caseInsensitive.sense
Last active May 11, 2018
Case Insensitive ElasticSearch Regular expressions
View caseInsensitive.sense
# Delete any old test index
DELETE example_copy
# Create index with appropriate mappings/settings
# Note that the pattern is meant to not match anything so that the entire field is taken as the "token"
PUT example_copy
{
"settings": {
"analysis": {
@EdgeCaseBerg
EdgeCaseBerg / VimeoClient.scala
Last active Apr 9, 2018
How to use Vimeo API from Scala
View VimeoClient.scala
import com.vimeo.networking._
import com.vimeo.networking.model._
import com.vimeo.networking.model.error.VimeoError;
import com.vimeo.networking.callbacks._
import java.io.File
import scala.concurrent.{Future, Promise}
import scala.reflect.ClassTag
import scala.reflect._
import okhttp3.CacheControl