Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Jester-Young cky

View GitHub Profile
@cky
cky / r1-log.md
Last active Jan 17, 2018
100 Days of Code challenge, round 1
View r1-log.md

#100DaysOfCode Log—Round 1—Chris Jester-Young

The log of my #100DaysOfCode challenge. Started on 1 January 2018.

Log

R1D1 (2018-01-01)

Created [SwiftJson] as a Swift port of [ktjson] and [c++17-json]. Coded up the basic JsonValue enum type.

@cky
cky / csp2pem.rb
Last active Dec 25, 2018
Quick script for converting PEM-format RSA keys to a format usable by .NET's RSA.FromXmlString
View csp2pem.rb
#!/usr/bin/ruby
require 'openssl'
TYPES = {
6 => {magic: 'RSA1', private_key: false},
7 => {magic: 'RSA2', private_key: true}
}
data = ARGV[0] ? File.binread(ARGV[0]) : $stdin.binmode.read
type, version, algo, magic, bits, rest = data.unpack('ccx2l<a4l<a*')
@cky
cky / flatten.js
Created Jun 12, 2016
One way to flatten in ES6, not necessarily the best
View flatten.js
function flatten(x) {
var result = [];
var appendToResult = function (xs) {
result.splice(result.length, 0, ...xs);
}
if (Array.isArray(x)) {
x.map(flatten).forEach(appendToResult);
} else {
result.push(x);
}
@cky
cky / miller-rabin.rkt
Last active Jun 2, 2016
My Miller-Rabin implementation (see http://codereview.stackexchange.com/a/129991/216 for context)
View miller-rabin.rkt
#lang racket
(define (expmod base exp m)
(let recur ([exp exp])
(cond [(zero? exp) 1]
[(even? exp) (let* ([prev (recur (quotient exp 2))]
[result (modulo (sqr prev) m)])
(if (and (< 1 prev (sub1 m))
(= result 1))
0
result))]
@cky
cky / area.rkt
Last active Mar 28, 2016
HackerRank Lambda Calculi March 2016: cky's answers
View area.rkt
#lang racket
(define (determinant p1 p2)
(- (* (car p1) (cdr p2))
(* (cdr p1) (car p2))))
(define points (read))
(define first (cons (read) (read)))
(define-values (area last)
(for/fold ([area 0] [last first])
([i (in-range (sub1 points))]
@cky
cky / in-nest-sequence.rkt
Last active Oct 16, 2015
`in-iterate` sequence generator
View in-nest-sequence.rkt
#lang racket
(require (for-syntax unstable/syntax))
(provide (rename-out [*in-nest-sequence in-nest-sequence]))
(define in-nest-sequence
(case-lambda
[(func init)
(make-do-sequence
(thunk (values identity func init #f #f #f)))]
[(func . inits)
@cky
cky / A.rkt
Last active Aug 29, 2015
Google Code Jam 2015 qualification round
View A.rkt
#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))
@cky
cky / Solution.java
Last active Aug 29, 2015
My solution for Sorted Set (Quora Haqathon 2014)
View Solution.java
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;
View keybase.md

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 / JnaCallbackDemo.java
Last active Aug 29, 2015
How to use JNA callbacks
View JnaCallbackDemo.java
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;
You can’t perform that action at this time.