Skip to content

Instantly share code, notes, and snippets.

View binki's full-sized avatar

Nathan Phillip Brink binki

View GitHub Profile
@binki
binki / gist:61513c005b87b120dc5d069ea5ed85e9
Created March 8, 2018 00:12
csharp hex can be unsigned if big enough
csharp> 0x80000000.GetType()
System.UInt32
csharp> 0x40000000.GetType()
System.Int32
@binki
binki / addUseStrict.js
Last active February 9, 2022 12:06
jscodeshift codemod to add "use strict" to any file where it is not already the first statement
module.exports = function (fileInfo, {
jscodeshift,
}, options) {
// Work around for https://github.com/facebook/jscodeshift/issues/262
const isUnix = fileInfo.source.indexOf('\r\n') === -1;
const dom = jscodeshift(fileInfo.source);
const topLevelStatements = jscodeshift(dom.get('program', 'body').value).filter(path => {
return jscodeshift.Statement.check(path.node);
});
// Don’t add another one if it is already there.
@binki
binki / find-likely-angular-injection-failures.sh
Last active June 11, 2018 17:33
Find old-style angular files likely to fail injection during minification
#!/bin/sh
# The find ignores any VS build folders and minified files. It
# then grabs any *.js and passes them to xargs.
#
# The xargs runs a script per each file which is unfortunately inside
# of "" so everything has to be escaped, making the inside unreadable.
# The sed takes any line ending in opening square bracket ‘[’, comma ‘,’,
# space ‘ ’ and removes the newline. It took me a long time to figure out
# how to get sed to join lines together. It involves some ridiculousness
@binki
binki / output.txt
Created June 11, 2018 20:39
demo gzip’s inability to do cross-archive deduplication
ohnobinki@gibby /tmp/.private/ohnobinki/testx $ LC_ALL=C ls -la
total 14636
drwxr-xr-x 2 ohnobinki users 120 Jun 11 20:37 .
drwx-----T 16 ohnobinki users 440 Jun 11 20:17 ..
-rw-r--r-- 1 ohnobinki users 3069158 Jun 11 20:17 IMG_20180327_165234.jpg
-rw-r--r-- 1 ohnobinki users 2939105 Jun 11 20:37 x.7z
-rw-r--r-- 1 ohnobinki users 5900455 Jun 11 20:18 x.tar.gz
-rw-r--r-- 1 ohnobinki users 3069158 Jun 11 20:17 x2.jpg
@binki
binki / gist:c8dfdf8ef3b7fde092f2b08ad235015a
Created June 18, 2018 15:16
Encoding.Default on Windows en-us
> System.Text.Encoding.Default.HeaderName
"Windows-1252"
@binki
binki / text.txt
Created June 26, 2018 15:17
text containing something that looks like an HTML/XML comment
a
<!-- hi -->
b
@binki
binki / glip-all-validate_string-excerpt-20180626.js
Last active September 25, 2018 13:53
Excerpt of Glip weird “do not send scripts” JavaScript
EC_Model.prototype.validate_string=function(a,b,c) {
if(!_.isNull(a)) {
if(_.isString(a)) {
if(a.length>b) {
return Errors.Too_Long(b);
}
if(a.match(/<script/gi)) {
return Errors.No_Script();
} }else {
return Errors.Invalid_Type();
@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)} |");
}
@binki
binki / gist:bf979cfaeb2ec503a2b6c96ee752de80
Created July 27, 2018 01:00
hexdump of extraneous carriage return in C# file CodeFixed to have missing using statement in visualstudio-15.7.5
binki@DESKTOP-QPI02O2 MSYS ~/source/repos/AddMissingUsingExtraneousCarriageReturn/AddMissingUsingExtraneousCarriageReturn
$ hexdump -C Class2.cs
00000000 ef bb bf 75 73 69 6e 67 20 53 79 73 74 65 6d 2e |...using System.|
00000010 49 4f 3b 0d 0a 75 73 69 6e 67 20 53 79 73 74 65 |IO;..using Syste|
00000020 6d 2e 54 65 78 74 2e 52 65 67 75 6c 61 72 45 78 |m.Text.RegularEx|
00000030 70 72 65 73 73 69 6f 6e 73 3b 0a 0a 6e 61 6d 65 |pressions;..name|
00000040 73 70 61 63 65 20 41 64 64 4d 69 73 73 69 6e 67 |space AddMissing|
00000050 55 73 69 6e 67 45 78 74 72 61 6e 65 6f 75 73 43 |UsingExtraneousC|
00000060 61 72 72 69 61 67 65 52 65 74 75 72 6e 0a 7b 0a |arriageReturn.{.|
00000070 20 20 20 20 63 6c 61 73 73 20 43 6c 61 73 73 32 | class Class2|
@binki
binki / build-precache-fixup.js
Created August 3, 2018 05:46
Work Around main.«hash».js missing from service-worker.js
#!/usr/bin/env node
// Works around issue described at
// https://github.com/facebook/create-react-app/issues/3574#issuecomment-410141752
// To use, add this as “&& ./build-precache-fixup.js” to
// package.json/scripts.build.
const crypto = require('crypto');
const fs = require('fs');
const path = require('path');