Skip to content

Instantly share code, notes, and snippets.

View notcome's full-sized avatar

Minsheng Liu notcome

View GitHub Profile
@notcome
notcome / sudoku.js
Created September 11, 2022 15:42
Sudoku v2
const zeroToEight = [0, 1, 2, 3, 4, 5, 6, 7, 8]
const oneToNine = zeroToEight.map(x => x + 1)
function rowCoords({ x, y }) {
return zeroToEight.map(i => { return { x, y: i } })
}
function colCoords({ x, y }) {
return zeroToEight.map(i => { return { x: i, y } })
}
@notcome
notcome / ChronoClockToUTC
Created July 8, 2014 07:31
Convert std::chrono::system_clock::time_point to std::tm
#include <iostream>
#include <ratio>
#include <chrono>
#include <string>
template <typename value_type>
struct timed {
std::chrono::time_point<std::chrono::steady_clock> timestamp;
value_type value;
@notcome
notcome / security.swift
Created April 10, 2018 01:01
Read and write RSA keys using Keychain Services
import Foundation
import CoreFoundation
import Security
/*
* Following operations will be supported:
* - generate a new keypair
* - export an existing keypair in PKCS12 format
* - delete an existing keypair
*
protocol DoSomething {
func f()
}
enum Empty {}
extension Empty: DoSomething {
func f() {}
}
@notcome
notcome / Suduko.js
Created June 6, 2019 01:29
A suduko solver that I wrote on DL89.
// This solver is semi-automaitc and you can see how possibilites are removed through each step.
// It turns out that the hard mode has more than one possible solution, so next time when you
// are stuck, just try one manually.
const zeroToEight = [0, 1, 2, 3, 4, 5, 6, 7, 8]
const oneToNine = zeroToEight.map(x => x + 1)
function rowCoords({ x, y }) {
return zeroToEight.map(i => { return { x, y: i } })
}
@notcome
notcome / main.swift
Created January 24, 2019 02:01
Tuned Swift for completely unscientific benchmark
// roughly 1.8x of best tuned solution.
// quite concerning since I have written a pool manually and added a GC for better cache locality.
import Foundation
struct Node {
var x: Int
var y: Int
var left: Int = -1
var right: Int = -1
import torch
import torch.nn as nn
import torch.nn.functional as F
vocabSize = 30000
hiddenSize = 128
batchSize = 16
seqSize = 128
class Net(nn.Module):
@notcome
notcome / install-desktop-apps.sh
Created March 26, 2018 05:27
Example of using Turtle
#!/usr/bin/env stack
-- stack runghc --package turtle
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Text.IO as T
import Turtle
exists :: MonadIO io => Text -> io Bool
exists cmd = do
@notcome
notcome / sb.hs
Created February 21, 2015 08:30
simplified boomerang in Haskell and PureScript
module Main where
import Prelude hiding (id, (.))
import Control.Category
import Control.Monad ((>=>))
import Data.List (stripPrefix)
type URL = [String]
type Route a = (URL, a)
@notcome
notcome / xelatex.sh
Created August 11, 2017 13:42
XeLaTeX inside Docker
#!/bin/sh
docker run \
-v $(pwd):/latex \
-v "/Users/selveskii/Library/Application Support/LaTeX/Styles":/styles \
-v "/Users/selveskii/Library/Application Support/LaTeX/Fonts":/fonts \
"minsheng/latex:latest" \
/bin/bash \
-c "export TEXINPUTS=\".:/styles:\"; xelatex $1"