Skip to content

Instantly share code, notes, and snippets.

Avatar
📠

nils måsén piksel

📠
View GitHub Profile
View SharpZipLib-561.cs
using (var outStream = new MemoryStream())
{
var zipOutputStream = new ZipOutputStream(outStream);
await outStream.FlushAsync(cancellationToken);
outStream.Seek(0, SeekOrigin.Begin);
zipOutputStream.SetLevel(CompressionMax);
foreach (var file in files)
{
using (var inStream = new MemoryStream())
{
View aoc2020-d5.cs
using System.IO;
using System.Collections.Immutable;
using System.Linq;
using static System.Linq.Enumerable;
using static ConLib.PrettyConsole;
var seats = new bool[0b1111111111];
foreach (var line in File.ReadLines("input.txt"))
seats[line.Select(s => "BR".Contains(s) ? 1 : 0).Aggregate(0, (a, b) => b | a << 1)] = true;
View aoc2020-d4.cs
using System.Linq;
using static System.IO.File;
using static System.Console;
using System.Text.RegularExpressions;
var required = new [] {"byr","iyr","eyr","hgt","hcl","ecl","pid"};
var eyecol = new [] {"amb", "blu", "brn", "gry", "grn", "hzl", "oth"};
bool numInRange(string y, int min, int max) => int.TryParse(y, out int yr) && yr >= min && yr <= max;
bool heightValid(string h)
View aoc2020-day3.cs
using System.Linq;
using static System.IO.File;
using static System.Console;
int GetTreeProd(string[] map, params (int x, int y)[] strats)
=> strats.Aggregate(1, (a, t) => a * Enumerable.Range(0, map.Length / t.y).Count(i => map[t.y * i][t.x * i % map[0].Length] == '#'));
var map = ReadAllLines("input.txt");
WriteLine($"Silver: {GetTreeProd(map, (3, 1))}");
WriteLine($"Gold: {GetTreeProd(map, (1,1), (3,1), (5,1), (7,1), (1,2))}");
@piksel
piksel / go.mod.diff
Last active Nov 22, 2020
Suggested go.mod for watchtower PR #674
View go.mod.diff
git diff origin/master -- go.mod
index 300eb31..d549e82 100644
--- a/go.mod
+++ b/go.mod
@@ -39,8 +39,8 @@ require (
github.com/lib/pq v1.2.0 // indirect
github.com/miekg/pkcs11 v0.0.0-20190401114359-553cfdd26aaa // indirect
github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c // indirect
- github.com/onsi/ginkgo v1.8.0
- github.com/onsi/gomega v1.5.0
@piksel
piksel / main.go
Created Jul 21, 2020
Go net/http default client proxy override
View main.go
package main
import (
"io/ioutil"
"log"
"net"
"net/http"
"net/url"
"time"
)
@piksel
piksel / build.Dockerfile
Last active May 10, 2020
Docker rebuild/update script
View build.Dockerfile
FROM node:12
WORKDIR /build
ADD package.json package-lock.json ./
RUN npm install && rm ./package*.json
@piksel
piksel / issue413.cs
Created Feb 1, 2020
Solution to SharpZipLib issue #413
View issue413.cs
using ICSharpCode.SharpZipLib.BZip2;
using System;
using System.Diagnostics;
using System.IO;
namespace Issue413
{
class Program
{
static void Main(string[] args)
View KeySeeder.cs
public class KeySeeder
{
const int KeySize = 8;
private Random random;
private int currIndex = 0;
private char[] keyBuffer = new char[KeySize];
private char[] keyChars = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-_".ToCharArray();
View interfacePropType.ts
import PropTypes from 'prop-types';
export function interfacePropType<T>(): PropTypes.Requireable<T> {
const validator = function(props: { [key: string]: any }, propName: string, componentName: string, location: string, propFullName: string)
{
return null;
}
validator.isRequired= function(props: {[key: string]: any}, propName: string, componentName: string){return null}