Skip to content

Instantly share code, notes, and snippets.

View jameshulse's full-sized avatar

James Hulse jameshulse

View GitHub Profile
@jameshulse
jameshulse / how.sh
Created January 12, 2024 22:16
Bash script to determine how a binary was installed
how() {
YELLOW='\033[1;33m'
NC='\033[0m'
if [[ "$1" == "" || "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: $0 <binary name>"
echo ""
echo "This will search for the binary in a few different places and try and determine how it was installed."
return 1
fi
@jameshulse
jameshulse / day-7.ex
Created December 8, 2022 08:28
Advent of Code 2022 - Day 7 (Elixer)
defmodule Day7 do
def part1(input) do
input
|> String.split("\n", trim: true)
|> Enum.reduce({"/", %{"/" => 0}}, &parse_command/2)
|> then(fn {_pwd, filesystem} -> get_directory_total_sizes(filesystem) end)
|> Enum.map(fn {_dir, size} -> size end)
|> Enum.filter(fn size -> size <= 100_000 end)
|> Enum.sum()
end
@jameshulse
jameshulse / day3.rs
Last active December 5, 2021 04:13
Advent of Code 2021 Day 3
use indoc::indoc;
use itertools::Itertools;
fn main() {
let lines = include_str!("input");
dbg!(part_one(lines));
dbg!(part_two(lines));
}
@jameshulse
jameshulse / day1.rs
Created December 2, 2021 06:23
AOC 2021 day1
use itertools::Itertools;
use std::fs;
fn main() {
let lines = fs::read_to_string("input.txt").expect("Couldn't read input file.");
let values: Vec<u32> = lines
.lines()
.map(|val| val.parse::<u32>().expect("Invalid value in input file!"))
.collect();
@jameshulse
jameshulse / Page.vue
Created May 30, 2018 21:05
Re-using component structure over multiple pages
<template>
<div>
<model-overview
:title="title"
:models="models"
@select="changeModel"
@add="createModel"
/>
<complex-form
@jameshulse
jameshulse / Controller.php
Last active July 17, 2017 03:10
Example of non-database bound model binding in Laravel routes
<?php
class Controller
{
function getData(Period $period)
{
return Model::where('created_at', '>', Carbon::create($period->year, $period->month, 1));
}
}
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="BlockInvalidHosts" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="*.justgiving.com" negate="true" />
</conditions>
public static class DeterministicGrouping
{
public static bool IsSelected(Guid entropy, ulong numerator, ulong denominator = 100)
{
if(numerator > denominator)
throw new ArgumentOutOfRangeException(nameof(numerator), "The numerator cannot be larger than the denominator.");
if (numerator <= 0)
throw new ArgumentOutOfRangeException(nameof(numerator), "The numerator must be a positive non-zero value.");
if (denominator <= 0)
throw new ArgumentOutOfRangeException(nameof(denominator), "The denominator must be a positive non-zero value.");
@jameshulse
jameshulse / TestDependencyResolver.cs
Last active January 8, 2016 16:07
DI() Resolver for Akka.NET Testing
public class TestDependencyResolver : IDependencyResolver
{
private readonly Dictionary<Type, Props> _registrations = new Dictionary<Type, Props>();
public void Register<T>(Props instance)
{
_registrations.Add(typeof(T), instance);
}
public Type GetType(string actorName)
public class CircularBuffer<T>
{
private readonly int _size;
private readonly T[] _items;
private int _writeLocation = -1;
private readonly object _lock = new object();
public CircularBuffer(int size)