Skip to content

Instantly share code, notes, and snippets.

View kornysietsma's full-sized avatar

Korny Sietsma kornysietsma

View GitHub Profile
const fooMembers = new Set([1,2]);
const barMembers = new Set([1,3]);
const groups: Map<Set<number>, String> = new Map();
groups.set(fooMembers,"foo");
groups.set(barMembers,"bar");
console.log(groups.get(fooMembers));
console.log(groups.get(new Set([1,2])));
@kornysietsma
kornysietsma / fetch_org_repos.rb
Created November 14, 2022 12:38
script to clone all repos for an organisation
#!/usr/bin/env ruby
require "graphql/client"
require "graphql/client/http"
require "json"
require 'set'
require 'pp'
MAX_PAGES = 999
#![forbid(unsafe_code)]
#![warn(clippy::all)]
#![warn(rust_2018_idioms)]
pub mod mymodule;
use std::ffi::OsString;
use std::fs;
use std::path::Path;
use std::path::PathBuf;
use std::process::Command;
@kornysietsma
kornysietsma / wait-until.clj
Created October 24, 2014 11:41
wait until in clojure test
(def default-wait-death (time/seconds 5))
(def default-wait-delay-ms 10)
(defn wait-until*
"wait until a function has become true"
([name fn] (wait-until* name fn default-wait-death))
([name fn wait-death]
(let [die (time/plus (time/now) wait-death)]
(loop []
(if-let [result (fn)]
@kornysietsma
kornysietsma / github_api.sh
Last active October 12, 2021 11:15
curl while hiding secrets for github api
#!/bin/bash -eu
# uses 1pass to get token from 1password vault
export GITHUB_API_TOKEN=`1pass "github api token"`
function ghapi() {
# escape double quotes as we need to insert the passed heredoc into a json string
# optionally we could build this with jq?
local json=$(cat | sed 's/"/\\"/g')
curl -sS -K <(cat <<<"header \"Authorization: token $GITHUB_API_TOKEN\"") -X POST https://api.github.com/graphql -d @- <<EOT
@kornysietsma
kornysietsma / wikiparse.clj
Last active January 2, 2021 18:41
parsing wikipedia dumps in clojure
(ns wikiparse.core
(:require [clojure.java.io :as io]
[clojure.data.xml :as xml]
[clojure.zip :refer [xml-zip]]
[clojure.data.zip.xml :refer [xml-> xml1-> text]])
(:import [ org.apache.commons.compress.compressors.bzip2 BZip2CompressorInputStream])
(:gen-class :main true))
(defn bz2-reader
"Returns a streaming Reader for the given compressed BZip2
@kornysietsma
kornysietsma / main.rs
Created September 7, 2019 18:17
byte regex fail
use regex::bytes::Regex;
fn main() {
let re = Regex::new(r"^(.*)$").unwrap();
let line: Vec<u8> = vec![
46, 45, 191, 87, 110, 176, 108, 158, 46, 45, 191, 87, 110, 176, 108, 158,
];
let s = std::str::from_utf8(&line);
if s.is_err() {
println!("Error in converting from utf8:{:?}", s);
@kornysietsma
kornysietsma / using_slow_to_string.rs
Created April 26, 2019 07:51
experimenting with rust traits and PartialEq
#![warn(clippy::all)]
#![allow(dead_code)]
use serde::ser::SerializeStruct;
use serde::ser::SerializeTuple;
use serde::{Serialize, Serializer};
use std::fmt;
use std::collections::HashMap;
use std::fmt::Debug;
@kornysietsma
kornysietsma / app.rs
Last active February 11, 2019 16:13
Slack actions and buttons in rust
extern crate actix;
extern crate actix_web;
extern crate bytes;
extern crate env_logger;
extern crate futures;
#[macro_use]
extern crate json;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
@kornysietsma
kornysietsma / github_releases.rb
Created June 1, 2018 12:53
Sample ruby code for paginated graphql queries
#!/usr/bin/env ruby
require 'graphql/client'
require 'graphql/client/http'
require 'json'
require 'pp'
require 'slop'
# The GraphQL gem _forces_ us to make the client a constant:
# https://github.com/github/graphql-client/blob/master/guides/dynamic-query-error.md