Skip to content

Instantly share code, notes, and snippets.

View kbridge's full-sized avatar

kq kbridge

  • Sunnydale
View GitHub Profile
@kbridge
kbridge / try_uv1.cpp
Last active February 11, 2019 12:25
uv different behavior under windows/linux
#include <stdio.h>
#include <stdlib.h>
#include <uv.h>
#include <chrono>
#include <thread>
using std::chrono::seconds;
using std::this_thread::sleep_for;
uv_fs_t open_req;
@kbridge
kbridge / periodic_worker-inl.h
Created August 30, 2019 09:40
spdlog periodic_worker workaround for MSVC
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#pragma once
#ifndef SPDLOG_HEADER_ONLY
#include "spdlog/details/periodic_worker.h"
#endif
namespace spdlog {
@kbridge
kbridge / lens.clj
Created August 14, 2021 14:32
lens implementation
(def p1
{:name "Danny",
:address {:country "Finland",
:city "Helsinki"}})
(defn lens [key]
(let [getter key
setter (fn [s a] (assoc s key a))]
(fn [fmap]
(fn [f]
@kbridge
kbridge / ForeverDemo.hs
Created September 25, 2021 17:11
Forever/MaybeT Demo
maybeBind :: IO (Maybe a) -> (a -> IO (Maybe b)) -> IO (Maybe b)
maybeBind x f =
x >>= \a ->
case a of
Just y -> f y
Nothing -> return Nothing
getLineMaybe :: IO (Maybe String)
getLineMaybe = getLine >>= \line -> return $ if null line then Nothing else Just line
import Data.IORef
newCounter :: IO (IO Int)
newCounter = do
n <- newIORef 0
return $ do
modifyIORef' n (+1)
readIORef n
-- GHCi:
@kbridge
kbridge / rluaguide.md
Created November 12, 2021 15:09
A list of tutorials and references so you can learn Roblox Lua

Roblox Scripting Guide

Written by Greenman#0001

The Roblox Wiki is one of the best ways to learn how to script but unfortunately, all of the tutorials on there have been scrambled due to the redesign so this guide is just sorting out the tutorials again so you can read them in the correct order. This guide should cover everything you need to become competent or at least confident with Roblox Lua.

Disclaimer

This will not guarantee that you will learn Lua quickly or even at all. It's your responsibility to use the resources here effectively by taking your time, taking notes, practicing, etc. This list will be updated as I find articles on important concepts that I overlooked so make sure you check back frequently.

@kbridge
kbridge / fix_docs.escript
Created March 26, 2022 17:50
erl help workaround for Fedora35/Erlang24.2.2-1
#!/usr/bin/env escript
%% Before
%% erl> h(maps). => There is no documentation for maps
%% After
%% erl> h(maps). => This module contains functions for maps processing...
%% Usage:
%%
%% 1. Install the documentation
@kbridge
kbridge / non-ascii.py
Created May 27, 2022 09:49
A line-oriented non-ascii byte finder, with unnecessary elegance
import sys
from typing import Iterator, Optional
ascii_range = range(32, 128)
def is_non_ascii(b):
return b not in ascii_range
def non_ascii_iter(bs):
return (b for b in bs if is_non_ascii(b))
@kbridge
kbridge / eigen-1.cpp
Last active May 30, 2022 15:11
A demo of using Eigen3 as a vector arithmetic library
// https://eigen.tuxfamily.org/dox/GettingStarted.html
// https://eigen.tuxfamily.org/dox/group__TutorialMatrixArithmetic.html
//
// SeeAlso: https://www.boost.org/doc/libs/1_79_0/libs/qvm/doc/html/index.html
#define EIGEN_INITIALIZE_MATRICES_BY_ZERO
#include <iostream>
#include <Eigen/Dense>
@kbridge
kbridge / weather_mar2012.csv
Last active June 5, 2022 15:14
A mirror of the weather data used in chapter 5 of pandas-cookbook (https://github.com/jvns/pandas-cookbook)
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 4.
"Longitude (x)","Latitude (y)","Station Name","Climate ID","Date/Time (LST)","Year","Month","Day","Time (LST)","Temp (°C)","Temp Flag","Dew Point Temp (°C)","Dew Point Temp Flag","Rel Hum (%)","Rel Hum Flag","Precip. Amount (mm)","Precip. Amount Flag","Wind Dir (10s deg)","Wind Dir Flag","Wind Spd (km/h)","Wind Spd Flag","Visibility (km)","Visibility Flag","Stn Press (kPa)","Stn Press Flag","Hmdx","Hmdx Flag","Wind Chill","Wind Chill Flag","Weather"
"-73.75","45.47","MONTREAL/PIERRE ELLIOTT TRUDEAU INTL A","7025250","2012-03-01 00:00","2012","03","01","00:00","-5.5","","-9.7","","72","","","","5","","24","","4.0","","100.97","","","","-13","","Snow"
"-73.75","45.47","MONTREAL/PIERRE ELLIOTT TRUDEAU INTL A","7025250","2012-03-01 01:00","2012","03","01","01:00","-5.7","","-8.7","","79","","","","6","","26","","2.4","","100.87","","","","-13","","Snow"
"-73.75","45.47","MONTREAL/PIERRE ELLIOTT TRUDEAU INTL A","7025250","2012-03-01 02:00","2012","03","01","02:00","-5.4","","-8.3","","80","","","","5","","28","","