Skip to content

Instantly share code, notes, and snippets.

View binki's full-sized avatar

Nathan Phillip Brink binki

View GitHub Profile
@CollinChaffin
CollinChaffin / How_to_disable_ATT_DNS_Redirection.md
Created August 29, 2018 21:26
How to disable the very little-known AT&T setting that can appear to hijack your home DNS lookups and redirect to 104.239.207.44

How to disable the very little-known AT&T setting that can appear to hijack your home DNS lookups and redirect to 104.239.207.44

Issue

DNS queries on home network suddenly resolving hosts to 104.239.207.44.

Symptoms

You will see SPORADIC mis-resolutions of EVERYTHING to that 104.239.207.44 address if their crappy router happens to hear your PC's DHCP request - EVEN IF ANOTHER DHCP SERVER ON THE NETWORK assigns the ultimate address.

@binki
binki / code.csx
Created July 6, 2018 14:38
Type.IsAssignableFrom Truth Table
Console.WriteLine("| `left` | `right` | `left.IsAssignableFrom(right)` |");
Console.WriteLine("| --- | --- | --- |");
var types = new[] {
typeof(object),
typeof(string),
};
foreach (var left in types) {
foreach (var right in types) {
Console.WriteLine($"| {left} | {right} | {left.IsAssignableFrom(right)} |");
}
@ljw1004
ljw1004 / tuple_perf.cs
Created April 20, 2017 15:02
Perf comparison ValueTuple vs Tuple vs KeyValuePair
// TUPLE MICRO-BENCHMARKS, based on https://www.dotnetperls.com/tuple-keyvaluepair
//
// Tuples are generally fastest.
// ValueTuple is fastest in the particular case of GetHashCode.
// KeyValuePair is always worst.
//
//
// RAW RESULTS
// Numbers in milliseconds (lower is better)
//
@binki
binki / Program.cs
Last active January 18, 2017 18:33
Play with C# string interpolation
using System;
namespace FormattablePlay
{
class Program
{
static void Main(string[] args)
{
var stringVar = "plant";
Append($"SELECT * FROM blah b WHERE b.Thing = {stringVar}");
@danverbraganza
danverbraganza / hangman.py
Last active April 20, 2017 18:52
Hangman implemented in 3 lines of Python! For an explanation of how this works, see http://danverbraganza.com/writings/hangman-in-3-lines-of-python
license, chosen_word, guesses, scaffold, man, guesses_left = 'https://opensource.org/licenses/MIT', ''.join(filter(str.isalpha, __import__('random').choice(open('/usr/share/dict/words').readlines()).upper())), set(), '|======\n| |\n| {3} {0} {5}\n| {2}{1}{4}\n| {6} {7}\n| {8} {9}\n|', list('OT-\\-//\\||'), 10
while not all(letter in guesses for letter in chosen_word) and guesses_left: _, guesses_left = map(guesses.add, filter(str.isalpha, raw_input('%s(%s guesses left)\n%s\n%s:' % (','.join(sorted(guesses)), guesses_left, scaffold.format(*(man[:10-guesses_left] + [' '] * guesses_left)), ' '.join(letter if letter in guesses else '_' for letter in chosen_word))).upper())), max((10 - len(guesses - set(chosen_word))), 0)
print 'You', ['lose!\n' + scaffold.format(*man), 'win!'][bool(guesses_left)], '\nWord was', chosen_word
@elsassph
elsassph / 1-loop-es6.js
Last active December 5, 2016 23:37
ES2015 / babel vs Haxe code generation
const a = [1,2,3];
var acc = 0;
for (const v of a) {
acc += v;
}
// want clean code? use Array.reduce
console.log(acc);
@ungoldman
ungoldman / curl_post_json.md
Last active April 15, 2024 14:46
post a JSON file with curl

How do you POST a JSON file with curl??

You can post a json file with curl like so:

curl -X POST -H "Content-Type: application/json" -d @FILENAME DESTINATION

so for example:

@jammycakes
jammycakes / LazyDisposable.cs
Last active December 26, 2022 22:31
A subclass of System.Lazy<T> that implements IDisposable and forwards calls to the Dispose method on to the lazily created instance if it exists.
/// <summary>
/// A <see cref="Lazy"/> object that implements <see cref="IDisposable"/>.
/// </summary>
/// <typeparam name="T">
/// The object being lazily created.
/// </typeparam>
public class LazyDisposable<T> : Lazy<T>, IDisposable where T: IDisposable
{
/// <summary>