Skip to content

Instantly share code, notes, and snippets.

View waf's full-sized avatar

Will Fuqua waf

View GitHub Profile
@waf
waf / Program.cs
Last active May 3, 2018 10:50
Fun with string interpolation
using System;
using System.Linq;
using System.Runtime.CompilerServices;
namespace Scratch
{
class Program
{
static void Main(string[] args)
{
@waf
waf / Program.cs
Created April 17, 2018 02:22
Testing memory usage when iterating IDictionary vs Dictionary
class Program
{
const int trials = 1_000_000;
static void Main(string[] args)
{
Dictionary<int, string> dict = Enumerable
.Range(1, 10)
.ToDictionary(number => number, number => number.ToString());
What is parsing?
Turning text (or some other stream of bytes) into a more useful format
- Turning strings into JSON objects
- Turning bytes into TCP packet structs
- Turning strings into some C# object hierarchy
Levels of parsing:
0 - avoid it -- use some standard format and library (json, xml, etc)
1 - string indexOf / split
2 - regex
@waf
waf / mobile_device_list.json
Created October 20, 2017 08:15
json from chromedriver's mobile_device_list.cc as of 2017-10-06
{
"iPad": {
"deviceScaleFactor": 2,
"mobile": true,
"height": 1024,
"width": 768,
"touch": true,
"userAgent": "Mozilla/5.0 (iPad; CPU OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1"
},
"Laptop with touch": {
@waf
waf / plank.idr
Created October 19, 2017 16:02
Plank script in idris
-- Counter app, count up in 30 seconds increments, and
-- then count down the last 10 seconds
module Main
import System
-- given a second, what should we say at that second?
sayWhatAt : Int -> String
sayWhatAt 30 = "30 seconds passed"
sayWhatAt 60 = "1 minute passed"
sayWhatAt seconds =
@waf
waf / plank-countdown-functional.ps1
Last active October 18, 2017 14:55
plank countdown script in more of a functional style
# main entry point
function Main
{
$total = 60 * 2 + 58
$timings = Generate-Timings -Total $total
Speak-Timings $timings
}
# int -> string[]
# generates an array of strings representing what should be said at each second.
Add-Type -AssemblyName System.Speech;
$synth = (New-Object System.Speech.Synthesis.SpeechSynthesizer)
$synth.SelectVoice("Microsoft Zira Desktop")
# speak the text, blocking the current thread
function Speak($text)
{
$synth.Speak($text)
}
@waf
waf / keybase.md
Created September 14, 2017 06:58

Keybase proof

I hereby claim:

  • I am waf on github.
  • I am wafuqua (https://keybase.io/wafuqua) on keybase.
  • I have a public key whose fingerprint is CB5A FF04 64BE 97B8 9FD3 190D 67B6 F489 167C 16A3

To claim this, I am signing this object:

@waf
waf / AddFive.Decompiled.cs
Created July 31, 2017 01:52
How are C# Local Functions Implemented
public static int AddFive(int a)
{
// object of a compiler-generated type is created
Program.<>c__DisplayClass1_0 cDisplayClass10 = new Program.<>c__DisplayClass1_0();
// reference to a compiler-generated field
cDisplayClass10.a = a;
// reference to a compiler-generated method
Program.<AddFive>g__InnerAdd1_0(5, ref cDisplayClass10);
// reference to a compiler-generated field
return cDisplayClass10.a;
@waf
waf / anki-import.py
Created February 23, 2017 12:16
Anki importer
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
sys.path.append('/Applications/Anki.app/Contents/Resources/lib/python2.7/site-packages.zip')
import anki
from anki.exporting import AnkiPackageExporter
TMPDIR="/tmp"
FBASENAME="thai"