Skip to content

Instantly share code, notes, and snippets.

View kbridge's full-sized avatar

kq kbridge

  • Sunnydale
View GitHub Profile
@kbridge
kbridge / non-exist-paths.st
Created September 25, 2023 16:16
tested on Glamorous Toolkit
| path sep dirs |
sep := (Smalltalk os isWindows) ifTrue: [ $; ] ifFalse: [ $: ].
path := Smalltalk os environment at: 'path'.
dirs := sep split: path.
dirs reject: [ :each | File exists: each ].
@kbridge
kbridge / main.cc
Created September 23, 2023 16:05
Query Installed Anti-Virus Software on Windows
// https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt
// https://source.chromium.org/chromium/chromium/src/+/main:base/win/scoped_com_initializer.h
// https://source.chromium.org/chromium/chromium/src/+/main:base/win/scoped_bstr.h
// https://source.chromium.org/chromium/chromium/src/+/main:chrome/services/util_win/av_products.cc (FillAntiVirusProductsFromWSC)
// C
#include <cassert>
#include <clocale>
@kbridge
kbridge / ifaddrs.c
Created June 18, 2023 18:23
demonstrate getifaddrs()
#include <linux/if_packet.h>
#include <net/if.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <ifaddrs.h>
#include <stdio.h>
#include <stdlib.h>
int
@kbridge
kbridge / chrome-hide-scroll-bars.js
Created June 10, 2023 16:04
keep you focus on the content without worrying about progress
var style = document.createElement('style');
style.innerHTML = 'html::-webkit-scrollbar { display: none; }';
document.head.appendChild(style);
@kbridge
kbridge / input-password.clj
Created May 6, 2023 04:42
clojure style exercise
;; style 1
(let [console (System/console)
password-char-array (.readPassword console "Password (hidden): " (to-array ()))
password (String. password-char-array)
quoted (fn [s] (str \' s \'))]
(println (quoted password)))
;; style 2
@kbridge
kbridge / 00_ToBinary.hs
Last active September 9, 2022 17:45
A complex implementation of integer to binary conversion in Haskell
import Data.Bits (Bits (testBit), FiniteBits(countLeadingZeros, finiteBitSize))
import Data.Char (intToDigit)
toBinary :: FiniteBits a => a -> [Char]
toBinary n = [charOfBitAt i n | i <- reverse [0..(bitLength n - 1)]]
where
bitLength = (-) <$> finiteBitSize <*> countLeadingZeros
charOfBitAt i = intToDigit . fromEnum . flip testBit i
@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","","
@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 / 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 / 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