Skip to content

Instantly share code, notes, and snippets.

@kflu
kflu / RateThrottleProgress.cs
Last active February 22, 2018 08:52
How to throttle upload speed using progress handler
/*
* RateThrottleProgress.cs
* Copyright (C) 2018 Kefei Lu
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@kflu
kflu / http-status.rkt
Last active July 24, 2017 05:21
parse http-status
#lang racket
(define-struct/contract http-status
([version string?]
[code (and/c positive? exact-integer?)]
[message string?])
#:transparent)
;; parse "HTTP/1.1 404 Not Found" into (http-status "HTTP/1.1" 404 "Not Found")
(define/contract (->http-status str)
@kflu
kflu / union-find.rkt
Created May 17, 2017 08:40
Union Find (disjoint sets) implemented in Racket. Refer to CLRS ch.21
#lang racket/base
(provide (all-defined-out))
(struct node (parent rank data) #:prefab #:mutable)
(define (make-set data)
(define res (node #f 0 data))
(set-node-parent! res res)
res)
@kflu
kflu / lis.py
Last active April 27, 2017 20:06
lispy
################ Lispy: Scheme Interpreter in Python
## (c) Peter Norvig, 2010-14; See http://norvig.com/lispy.html
################ Types
from __future__ import division
Symbol = str # A Lisp Symbol is implemented as a Python str
List = list # A Lisp List is implemented as a Python list
@kflu
kflu / ListDevice.cs
Created March 13, 2017 18:39
List hardware devices
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
@kflu
kflu / webapi.cs
Created February 15, 2017 01:00
Vanilla self host ASP.NET web API application
namespace Foo
{
using System;
using System.Net;
using System.Threading;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
@kflu
kflu / cmdline.rkt
Created February 13, 2017 07:43
Racket command line use
#| This script demos the use of command line library. Note the use
of parameters, and the effort of encapsulating them in the local
bound function variables.
|#
#lang racket
(define [file-to-compile argv]
(let ([verbose-mode (make-parameter #f)]
[profiling-on (make-parameter #f)]
@kflu
kflu / common.fs
Created January 9, 2017 22:04
common.fs
let (?=) x y = System.String.Equals(x, y, StringComparison.InvariantCultureIgnoreCase)
@kflu
kflu / _note.md
Last active January 9, 2017 19:04
.NET Queue is rotational.

.NET Queue is rotational.