Skip to content

Instantly share code, notes, and snippets.

View cky's full-sized avatar

C. K. Young cky

View GitHub Profile
@cky
cky / gist:7533352
Created November 18, 2013 19:01
Stack Overflow [code-golf] tag info
@cky
cky / gist:8500450
Last active June 21, 2022 02:25
Guile implementation of Clojure's `#(...)` reader macro, but using `##(...)` instead to avoid conflicting with vectors.
(use-srfis '(1 69))
(read-hash-extend #\#
(lambda (c port)
(define ht (make-hash-table eqv?))
(define (ht-ref key)
(hash-table-ref ht key (lambda ()
(define sym (gensym))
(hash-table-set! ht key sym)
sym)))
(define (hash-key x)
@cky
cky / pollute.rkt
Last active January 4, 2016 04:59
Gauche-style ^ macros for all combinations of one and two letters. Hi, Mark Weaver!
(define-syntax pollute-my-namespace
(let ((letters "abcdefghijklmnopqrstuvwxyz_")
(char->symbol (compose string->symbol string)))
(define (make-macros stx)
(lambda ()
(for*/lists (ids syntaxes)
((x letters)
(y letters))
(if (char=? x y)
(values (datum->syntax stx (char->symbol #\^ x))
@cky
cky / A.rkt
Created April 13, 2014 02:32
Google Code Jam 2014 Qualification
#lang racket
(define (get-candidates)
(define row (sub1 (read)))
(for/seteqv ((i (in-range 16))
(item (in-producer read))
#:when (= (quotient i 4) row))
item))
(define T (read))
(for ((c (in-range T)))
import java.util.Arrays;
/**
* Demonstration of bound method references.
*/
public class MethodReferenceExample1 {
public static void main(String[] args) {
Arrays.stream(args, 1, args.length).filter(args[0]::contains)
.forEach(System.out::println);
}
@cky
cky / sha12.scm
Last active June 12, 2021 14:00
Scheme implementation of SHA1 and SHA2
;;;; SHA-1 and SHA-2 implementations.
;;;; Uses R7RS bytevector and byte I/O interfaces.
;;;; Requires SRFIs 1, 26, 43, and 60.
;;; Auxiliary definitions to avoid having to use giant tables of constants.
(define primes80 '(2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73
79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157
163 167 173 179 181 191 193 197 199 211 223 227 229 233 239
241 251 257 263 269 271 277 281 283 293 307 311 313 317 331
@cky
cky / JnaCallbackDemo.java
Last active August 29, 2015 14:03
How to use JNA callbacks
package nz.kiwi.chris.demo;
import java.util.Arrays;
import java.util.Comparator;
import com.sun.jna.Callback;
import com.sun.jna.Function;
import com.sun.jna.IntegerType;
import com.sun.jna.Library;
import com.sun.jna.Native;
@cky
cky / keybase.md
Created September 26, 2014 11:59

Keybase proof

I hereby claim:

  • I am cky on github.
  • I am cky (https://keybase.io/cky) on keybase.
  • I have a public key whose fingerprint is D452 5B49 1CE4 D047 1BFF 1090 8E54 9D02 234C C324

To claim this, I am signing this object:

@cky
cky / Solution.java
Last active August 29, 2015 14:11
My solution for Sorted Set (Quora Haqathon 2014)
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@cky
cky / A.rkt
Last active August 29, 2015 14:19
Google Code Jam 2015 qualification round
#lang racket
(for ((c (in-range (read)))
(smax (in-port))
(line (in-port (compose string-trim read-line))))
(define-values (extras total)
(for/fold ((extras 0) (total 0))
((i (in-range (add1 smax)))
(j (in-string line)))
(define n (- (char->integer j) (char->integer #\0)))
(define cur-extras (max (- i total) 0))