Skip to content

Instantly share code, notes, and snippets.

View SleeplessByte's full-sized avatar
💎
💎 💎 💎

Derk-Jan Karrenbeld SleeplessByte

💎
💎 💎 💎
View GitHub Profile
@SleeplessByte
SleeplessByte / helper_array_to_listing.php
Last active April 28, 2024 09:26
Creates a human readable list of an array, implodes all items, but combines last two first.
<?php
/**
* Creates a human readable list of an array
*
* @param string[] $ranges array to list items of
* @param string $glue normal glue between items
* @param string $last glue between last two items
*
* @remarks works with 0, 1, 2 or 3+ items
* @returns string 'item1, item2, item3 or item4'
@SleeplessByte
SleeplessByte / .gradle
Created January 24, 2015 23:51
Android Studio - How to gitignore your signing.
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile [...]
}
android {
// Add a gradle.properties to your root to make this workd:
@SleeplessByte
SleeplessByte / useColorScheme.ts
Created February 18, 2020 20:44
Hooks and Contexts to deal with react-native-appearance. Automatically updates and persists changes.
import React, { useMemo } from "react";
import {
createContext,
useContext,
useState,
useEffect,
useCallback
} from "react";
import {
Appearance,
@SleeplessByte
SleeplessByte / contributions.md
Last active May 14, 2021 17:23
Exercism contributions

I really don't like the notion where we look at commit counts (that's code style), line count (quantity/quality, and highly different per language) or even time investment (indication of efficiency, not effort), so I've only listed the projects and the additions and leave it up to managment to make some pragmatic choices for rewards.

This is a non-comprehensive list of things I think I contributed, which others can use as a basis for their own list.

Tooling I've written from scratch

@SleeplessByte
SleeplessByte / .gitattributes
Last active February 3, 2021 14:57
.gitattributes that will make development on Windows Great Again
# Handle line endings automatically for files detected as text
# and leave all files detected as binary untouched.
* text=auto
# Force the following filetypes to have unix eols, so Windows does not break them
*.* text eol=lf
# Windows forced line-endings
/.idea/* text eol=crlf
@SleeplessByte
SleeplessByte / aoc-2020-d16.rb
Last active December 17, 2020 00:19
Advent of Code 2020: Day 16 - Ticket Translation
rules, yours, nearby = File.read('input.txt').split(/\n\n/)
def ticket_values(nearby)
nearby.split("\n")[1..]
end
def category_values(rules)
rules.split("\n").each_with_object({}) do |line, categories|
next if line.empty?
@SleeplessByte
SleeplessByte / aoc-2020-d15.rb
Created December 15, 2020 16:36
Advent of Code 2020: Day 15 - Rambunctious Recitation
numbers = File.read('input.txt').chomp.split(',').map(&:to_i)
turns = numbers.dup
memory = Hash.new { [] }
numbers.each_with_index do |number, turn|
memory[number] = [turn]
puts "Turn #{turn + 1}: #{number}"
end
@SleeplessByte
SleeplessByte / aoc-2020-d14.rb
Last active December 14, 2020 21:21
Advent of Code 2020: Day 14 - Docking Data
require 'benchmark'
def mask_rjust(value, mask)
value.to_s(2).rjust(mask.length, "0")
end
def mask_from_line(maskline)
mask = maskline.chomp.split('mask = ').last
add = mask.tr('01X', '010').to_i(2)
sub = mask.tr('01X', '011').to_i(2)
@SleeplessByte
SleeplessByte / aoc-2020-d13.rb
Created December 13, 2020 23:22
Advent of Code 2020: Day 13 - Shuttle Search
require 'prime'
require 'benchmark'
source = 'input.txt'
timestamp, schedule_line = File.readlines(source)
schedule = schedule_line.split(',').map { |x| x.chomp }
busses = schedule
.each_with_index
@SleeplessByte
SleeplessByte / aoc-2020-d12.rb
Last active December 12, 2020 11:08
Advent of Code 2020: Day 12 - Rain Risk
require 'benchmark'
class Ship
attr_reader :position
def initialize
self.facing = 90
self.position = Position.new(0, 0)
self.waypoint = Waypoint.new