Skip to content

Instantly share code, notes, and snippets.

View chrismay's full-sized avatar

Chris May chrismay

  • Warwickshire, UK
View GitHub Profile
@chrismay
chrismay / tuples.ts
Created June 21, 2023 18:31
Preserve tuple length when mapping
interface ReadonlyArray<T> {
map<U>(
callbackfn: (value: T, index: number, array: T[]) => U,
thisArg?: any
): { [K in keyof this]: U };
}
type Coord = readonly [number, number, number];
type BiFunction<T> = (a: T, b: T) => T;
@chrismay
chrismay / parallel_reqs.py
Last active June 18, 2023 21:32
pyspark parallel http reqs
import aiohttp
import asyncio
import time
from pyspark.sql import SparkSession
from pyspark.sql.functions import col, collect_list,udf
spark = SparkSession.builder.getOrCreate()
data = range(1, 10000)
df = spark.createDataFrame([(i,) for i in data], ["value"])
grouped_df = (
@chrismay
chrismay / anagrams.py
Created April 12, 2023 06:55
anagrams kata (pyspark)
from pyspark.sql import SparkSession
from pyspark.sql.types import StringType
from pyspark.sql.functions import col, udf, collect_list, size, length
spark = SparkSession.builder.getOrCreate()
def alpha_sort(word):
return "".join(sorted(word))
import { Instant } from '../types';
type NotificationType = 'po-approval' | 'program-activation';
interface NotificationSharedFields {
referenceId: string;
message: string;
seen: boolean;
createdAtUtc: Instant;
notificationType: NotificationType;
if ($host.Name -eq 'ConsoleHost') {
Set-PSReadLineOption -EditMode Emacs
Set-PSReadlineOption -BellStyle None
}
# Ensure that Get-ChildItemColor is loaded
Import-Module Get-ChildItemColor
# Set l and ls alias to use the new Get-ChildItemColor cmdlets
Set-Alias ll Get-ChildItemColor -Option AllScope
Set-Alias ls Get-ChildItemColorFormatWide -Option AllScope
@chrismay
chrismay / Hyper-settings.js
Last active August 10, 2018 07:11
Hyper seting
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// choose either `'stable'` for receiving highly polished,
// or `'canary'` for less polished but more frequent updates
updateChannel: "canary",
@chrismay
chrismay / cold_observable_test.ts
Created August 1, 2018 11:23
Jasmine/Karma test of cold observables
it('delete me', async (done) => {
const addAll = nums => nums.reduce((a, b) => a + b, 0);
const o1 = Observable.of(1);
const o2 = Observable.of(2).delay(1000).shareReplay(1);
const o1p2 = Observable.forkJoin([o1, o2]).pipe(
map(addAll),
shareReplay(1));
@chrismay
chrismay / LambdaLogger.js
Created June 21, 2018 09:40
A lambda to unpack the POST body (assumed to be JSON) and log it to cloudwatch
exports.handler = async (event, ctx, callback) => {
console.log({app:"unknown", env: "unknown", ...(JSON.parse(event.body))});
var response = {
"statusCode": 200,
"body": JSON.stringify({result:"ok"}),
"isBase64Encoded": false
};
callback(null,response);
};
@chrismay
chrismay / Hamilton.java
Last active October 22, 2017 19:25
An implementation of Hamilton's method for Smallest-Remainder rounding of percentages.
package chris.impl;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.function.Function;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
@chrismay
chrismay / loop.html
Last active October 11, 2016 14:09
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> - jsFiddle demo</title>
<style type='text/css'>
</style>