Skip to content

Instantly share code, notes, and snippets.

@davidair
davidair / EasyString.swift
Created October 12, 2017 14:54
Example of an easier string in Swift (not optimized)
/*
Copyright 2017 Google Inc.
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
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@davidair
davidair / wikipedia_to_fen.py
Last active December 8, 2017 20:24
Convert Wikipedia Chess Diagram to FEN
#!/usr/bin/python
# Copyright 2017 Google LLC.
#
# 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
#
# https://www.apache.org/licenses/LICENSE-2.0
#
#include <iostream>
#include <sstream>
void IterativeNestedLoop(int depth, int max, std::function<void(int* slots, int)> action)
{
// Initialize the slots to hold the current iteration value for each depth
int* slots = (int*)alloca(sizeof(int) * depth);
for (int i = 0; i < depth; i++)
{
slots[i] = 0;
@davidair
davidair / AsyncActivity.kt
Created November 9, 2018 23:12
A base class activity that leverages Kotlin coroutines and allows streamlining activity invocation
/**
* Copyright 2017 Google LLC.
*
* 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
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
var additionalFakeForecasts = {
'2357536' : {
key: '2357536',
label: 'Austin, TX',
created: '2016-07-22T01:00:00Z',
channel: {
astronomy: {
sunrise: "5:43 am",
sunset: "8:21 pm"
},
function fetchCall() {
const Http = new XMLHttpRequest();
const host = window.location.href.substring(0, window.location.href.indexOf(window.location.pathname));
const url = host + "/?file=1mb";
Http.open("GET", url);
Http.send();
Http.onreadystatechange = (e) => {
if (Http.readyState == XMLHttpRequest.DONE) {
document.getElementById("test_result").value = document.getElementById("test_result").value +
"\nReceived data, chunks remaining: " + _chunks;
@davidair
davidair / Program.cs
Last active June 22, 2020 22:24
Example on how to save a shortcut with PKEY_AppUserModel_ID
/**
* Copyright 2020 Google LLC.
* SPDX-License-Identifier: MIT
*/
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;
using System;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@davidair
davidair / MainForm.cs
Last active August 12, 2022 06:39
Sample for self-registering desktop C# app that creates and reacts to toasts
/**
* Copyright 2020 Google LLC.
* SPDX-License-Identifier: MIT
*/
using Microsoft.Toolkit.Uwp.Notifications;
using System;
using System.Windows.Forms;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
@davidair
davidair / dyncode_wiki.py
Last active March 8, 2021 23:53
Selenium-based harness that dynamically evaluates code to allow exploring web automation without re-running the driver
# Copyright 2021 Google LLC.
# SPDX-License-Identifier: Apache-2.0
search_input = driver.find_element_by_xpath("//input[@id='searchInput']")
search_input.clear()
search_input.send_keys('George Washington')
submit_button = driver.find_element_by_xpath("//button[@type='submit']")
submit_button.click()
@davidair
davidair / renamer.py
Created April 11, 2021 04:59
Filename renamer for TD Canada Trust statements to normalize timestamps
# Copyright 2021 Google LLC.
# SPDX-License-Identifier: Apache-2.0
import os
import pathlib
import re
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
pattern_td = r'(.+)([A-Za-z]{3})_(\d\d)-([A-Za-z]{3})_(\d\d)\_(\d\d\d\d).pdf'
pattern_loc = r'(.+)([A-Za-z]{3})_(\d\d)(_|-)(\d\d\d\d).pdf'