Skip to content

Instantly share code, notes, and snippets.

View willeccles's full-sized avatar
🖤
probably out driving

Will Eccles willeccles

🖤
probably out driving
View GitHub Profile
@willeccles
willeccles / methoding.java
Last active August 26, 2015 22:00
an even better way to pass methods as parameters
public static void main(String[] args) {
// this uses a java 8 feature called method references (i think)
// it looks for method "aThingToDo" in class "methoding" (the name of this class)
// aThingToDo must match the pattern, as doAThing says
doAThing(methoding::aThingToDo);
}
// define a pattern for what type of method we want
// we want a method with String s as input and no return (void)
public interface voidMethod {
@willeccles
willeccles / gist:25684fd010b5f71353f0
Last active August 29, 2015 14:24
Make a div round
/* to make a div round, the width and height must be the same (a square)
also, the border radius must be half of the w/h
so for a div 42x42, the radius should be 21. */
.my-round-div {
background-image: url("my-square-or-round-image.png");
display: block;
height: 42px;
width: 42px;
/// test #1
#define u using
#define n namespace
#define s std
// so can this work?
u n s;
// yes indeed it can!
/// test #2
@willeccles
willeccles / pass a method to a method.java
Created August 14, 2015 22:48
This is how to pass a method to another method in Java 8+.
// while this is not technically a method, a Runnable is close enough for me.
// this method wants a "method" as an input
void canHazMethod(Runnable methodToRun) {
// run the method passed in
methodToRun.run();
}
// this is the method I will use:
Runnable myMethod = () -> {
@willeccles
willeccles / Day8.cpp
Last active December 8, 2015 22:13
Part 1 of Day 8 of Advent of Code. The reason for it being a whole new class called Day8 is that I use a single main.cpp to run each day's code, just instantiating a Day6, 7, 8, etc... and using the run() method.
#include "stdafx.h"
#include "Day8.h"
#include <iostream>
#include <string>
#include <fstream>
#include <regex>
using namespace std;
// this is just to make my code later on cleaner and simpler, whereas up here I don't really care.
@willeccles
willeccles / Day9.cpp
Created December 9, 2015 22:42
This is how I did Day9. Not the most efficient, but I am lazy and am willing to wait a bit longer. Also, this /can/ be wrong, but most likely won't be.
#include "stdafx.h"
#include "Day9.h"
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <algorithm>
#include <map>
using namespace std;
@willeccles
willeccles / github powershell.ps1
Created April 8, 2016 20:59
A few git-related methods for PowerShell.
# Set up the github profile, as outlined in the profile itself.
# this will only work if you have installed github desktop
. (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1")
clear
#on this line I run archeyjs, but I removed that here.
# define your github folder path
$gitfolder="C:\path\to\github\folder"
#include <iostream>
#include <regex>
#include <string>
#include <fstream>
#include <vector>
#include <ctime>
#include <thread>
using namespace std;
@willeccles
willeccles / speakfile.sh
Last active August 13, 2016 17:09
Bash file to speak a file out loud on OS X, with options for volume, voice, and interactive reading.
#! /bin/bash
if (( $# == 1 )) && [ "$1" == "?" ]
then
say -v ?
echo ""
echo "Voices should be specified in quotes if 2+ words."
exit 0
fi
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int place = 1;
int places = 100;
int main(int argc, char* argv[]) {
if (argc >= 3) {
places = atoi(argv[2]);