Skip to content

Instantly share code, notes, and snippets.

View niuk's full-sized avatar

Kangyuan Niu niuk

View GitHub Profile
@niuk
niuk / gist:967c2405532746aabbe3e9b376172157
Created April 28, 2023 21:04
Conversation with Bing regarding motorcycle skid plates
why are motorcycle skid plates not attached via damped springs?
Sent message. why are motorcycle skid plates not attached via damped springs?
Searching for: motorcycle skid plates
Searching for: motorcycle skid plates
Searching for: motorcycle skid plates damped springs
Searching for: motorcycle skid plates damped springs
@niuk
niuk / jwt_oauth.cpp
Created April 15, 2021 22:38
Google OAuth JWT in C++
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#define CPPHTTPLIB_OPENSSL_SUPPORT
#include "httplib.h"
@niuk
niuk / doodle.txt
Last active April 24, 2020 07:42
What System-F• could look like?
type Maybe: * -> *
Just: forall t: *. t -> Maybe t
Nothing: forall t: *. Maybe t
type Array: * -> 1 -> *
type Array t a = {
length: a -> (Int, a),
get: (Int, a) -> (t, a),
set: (Int, t, a) -> a,
}
@niuk
niuk / JavaScriptCore.cs
Created March 3, 2017 01:01
JavaScriptCore wrapper; doesn't work, but could serve as a starting point for something that does.
using System;
using System.Runtime.InteropServices;
using JSObject = WebKit.JSValue;
using JSGlobalContext = WebKit.JSContext;
namespace WebKit {
#region JSBase.h
public unsafe struct JSContextGroup { }
@niuk
niuk / Xorg.1.log
Last active August 27, 2015 04:10
[ 1782.724]
X.Org X Server 1.17.2
Release Date: 2015-06-16
[ 1782.724] X Protocol Version 11, Revision 0
[ 1782.724] Build Operating System: Linux 3.16.0-4-armmp-lpae armv7l Debian
[ 1782.725] Current Operating System: Linux localhost 3.10.18 #1 SMP Sun Aug 16 14:15:42 PDT 2015 armv7l
[ 1782.725] Kernel command line: cros_secure console= loglevel=7 init=/sbin/init cros_secure oops=panic panic=-1 root=/dev/dm-0 rootwait ro dm_verity.error_behavior=3 dm_verity.max_bios=-1 dm_verity.dev_wait=1 dm="1 vroot none ro 1,0 2506752 verity payload=PARTUUID=05eceb2f-a0f6-e148-aeff-922d1e46d1be/PARTNROFF=1 hashtree=PARTUUID=05eceb2f-a0f6-e148-aeff-922d1e46d1be/PARTNROFF=1 hashstart=2506752 alg=sha1 root_hexdigest=33a9d721e0081c18fc5116be68b2371d8b47af7b salt=5e4abdb7e295d69bb864ad580f75c8ce3a141b49b05233e292f995be6e64d932" noinitrd vt.global_cursor_default=0 kern_guid=05eceb2f-a0f6-e148-aeff-922d1e46d1be
[ 1782.729] Build Date: 11 August 2015 10:08:33AM
[ 1782.729] xorg-server 2:1.17.2-1.1 (http://www.debian.or
data Op = Plus | Minus | Concat deriving Show
f l = concatMap (\r -> map (: r) l)
step :: Int -> Op -> (Int, Int) -> (Int, Int)
step digit op (carry, sum) = case op of
Concat -> (digit * 10 ^ ceiling (logBase 10 (fromIntegral carry)) + carry, sum)
Plus -> (digit, sum + carry)
Minus -> (digit, sum - carry)
1: Env _ (fromList [])
(lambda {f x y: f (x y)}) (lambda {x: x}) (lambda {f x: x f}) (lambda {x y: y})
1: Env _ (fromList [])
(lambda {f x y: f (x y)}) (lambda {x: x}) (lambda {f x: x f})
1: Env _ (fromList [])
(lambda {f x y: f (x y)}) (lambda {x: x})
1: Env _ (fromList [])
execve("/usr/local/bin/perl", ["perl", "--version"], [/* 55 vars */]) = 0
brk(0) = 0x132c000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6c0e678000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/usr/lib/perl5/core_perl/CORE/tls/x86_64/libperl.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/perl5/core_perl/CORE/tls/x86_64", 0x7fff3d538980) = -1 ENOENT (No such file or directory)
open("/usr/lib/perl5/core_perl/CORE/tls/libperl.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/perl5/core_perl/CORE/tls", 0x7fff3d538980) = -1 ENOENT (No such file or directory)
open("/usr/lib/perl5/core_perl/CORE/x86_64/libperl.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/perl5/core_perl/CORE/x86_64", 0x7fff3d538980) = -1 ENOENT (No such file or directory)
@niuk
niuk / ER.hs
Created February 17, 2012 23:57
Slow as molasses.
import Data.Array
import Data.Graph
import Data.IORef
import System.Random
import Control.Monad
main = do
graphRef <- newIORef .
array (1, 1000) $ zip [1 .. 1000] (repeat [])
let f = do
@niuk
niuk / gist:1682420
Created January 26, 2012 11:50
This runs just fine.
#include <stdbool.h>
#include <stdio.h>
#include <llvm-c/Core.h>
#include <llvm-c/ExecutionEngine.h>
int main(int argc, char **argv) {
LLVMLinkInJIT();
if (LLVMInitializeNativeTarget()) {
fprintf(stderr, "Failed to initialize native target.\n");