Skip to content

Instantly share code, notes, and snippets.

View cameronism's full-sized avatar

Cameron Jordan cameronism

View GitHub Profile
@cameronism
cameronism / rfkill-toggle.sh
Created November 14, 2015 04:05
rfkill-toggle.sh
#!/bin/sh
# Usage ./rfkill-toggle.sh [IDENTIFIER]
# where IDENTIFIER is the index no. of an rfkill switch or one of:
# wifi wlan bluetooth uwb ultrawideband wimax wwan gps fm nfc
ID=`rfkill list "$1" | head -c 1 | cut -f 1`
SOFT="/sys/class/rfkill/rfkill$ID/soft"
if [ ! -f "$SOFT" ]; then
@cameronism
cameronism / index.html
Created September 30, 2020 00:00
Super Mario Maker 2 Bingo
<div>
<h1>Super Mario Maker <em>2</em> Bingo</h1>
<table></table>
<fieldset>
<legend>Options</legend>
<textarea rows=24></textarea>
<label>Seed <input type=number></label>
<button class=run>Let's Go</button>
<button class=reset>Start Over</button>
#include <iostream>
#include <Windows.h>
#include <string>
#include <codecvt>
// https://stackoverflow.com/questions/14762456/getclipboarddatacf-text
std::wstring GetClipboardText()
{
// Try opening the clipboard
if (!OpenClipboard(nullptr))
@cameronism
cameronism / TakeDescending.cs
Created February 27, 2019 01:48
Take top n items from IEnumerable<> efficiently
public static IReadOnlyCollection<T> TakeDescending<T, TKey>(IEnumerable<T> source, Func<T, TKey> keySelector, int count)
where TKey : IComparable<TKey>
{
var index = 0;
var keys = new TKey[count];
var values = new T[count];
TKey min = default;
var minIndex = 0;
foreach (var item in source)
@cameronism
cameronism / QuickAsciiReader.cs
Last active November 19, 2018 19:10
High speed TextReader-like object. Almost 3x faster than StreamReader + MemoryStream
/// <summary>
/// High speed TextReader-like object, wraps a byte array directly rather than a Stream
/// Almost 3x faster than StreamReader + MemoryStream in my tests
/// </summary>
public struct QuickAsciiReader
{
private readonly byte[] _Array;
private int _Index;
private readonly int _End;
@cameronism
cameronism / jsondiff.cs
Last active March 14, 2018 04:36
JObject based JSON diff
void Main()
{
var pairs = new (object, object)[]
{
(new {}, new {}),
(new { a = 1 }, new { a = "1" }),
(new { a = "1", b = 2 }, new { a = 1 }),
(new { a = "1", c = 2 }, new { a = 1, c = 2 }),
(new { a = "1", c = new {} }, new { a = 1, c = new {} }),
(new { a = new { a = 1 } }, new { a = new {} }),
@cameronism
cameronism / .luacheckrc
Created August 12, 2017 17:33
pico-8 luacheck configuration file (luacheckrc)
std = {
-- these globals can be set and accessed.
globals = { "_init", "_draw", "_update", "_update60" },
-- these globals can only be accessed.
read_globals = {
--[[
copy(
`-- from ${location.href} ${(new Date()).toISOString()}\n` +
[].slice.call($('#WikiaMainContent').find('ul>li>a,.mw-headline'))
@cameronism
cameronism / Demo.cs
Created May 11, 2017 16:48
ShallowValueComparer
void Main()
{
// http://stackoverflow.com/questions/263400/what-is-the-best-algorithm-for-an-overridden-system-object-gethashcode
Demo(new { }, new { });
Demo(null, new { });
Demo(new { }, null);
Demo(new { a = 1 }, new { a = 1 });
//new { _1 = HashInt(1), _2 = HashInt(2) }.Dump();
Demo(new { a = 1 }, new { a = 2 });
@cameronism
cameronism / dev-tools-ftw.js
Created February 12, 2017 22:38
streamline photopass downloads
// 1. pay for all your photos
// 2. scroll through the entire album and ensure all previews have loaded
// 3. open dev tools
var stopDownloadPlease = false;
var downloadPlease = () => { setTimeout(() => {$(".icon-button.download").click(); setTimeout(() => { $(".arrow-next .icon.ng-binding.wdw.size-l.rotate-0").click(); if (!stopDownloadPlease) { downloadPlease() }; }, 4000)}, 700) };
downloadPlease();
// 4. watch downloads folder until duplicates start showing up (or some other way to make sure you got them all)
// 5. `stopDownloadPlease = true;`
@cameronism
cameronism / LICENSE
Created October 12, 2016 01:30
Extension functions on JDBC Connection and ResultSet
Copyright 2016 Cameron Jordan
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,