Skip to content

Instantly share code, notes, and snippets.

Avatar

Minsheng Liu notcome

  • XNZG
  • Hangzhou, China
View GitHub Profile
View sudoku.js
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 Jul 8, 2014
Convert std::chrono::system_clock::time_point to std::tm
View ChronoClockToUTC
#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 Apr 10, 2018
Read and write RSA keys using Keychain Services
View security.swift
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
*
View uninhabited-in-struct.swift
protocol DoSomething {
func f()
}
enum Empty {}
extension Empty: DoSomething {
func f() {}
}
@notcome
notcome / Suduko.js
Created Jun 6, 2019
A suduko solver that I wrote on DL89.
View Suduko.js
// 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 Jan 24, 2019
Tuned Swift for completely unscientific benchmark
View main.swift
// 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
View minimal.py
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 Mar 26, 2018
Example of using Turtle
View install-desktop-apps.sh
#!/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 Feb 21, 2015
simplified boomerang in Haskell and PureScript
View sb.hs
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 Aug 11, 2017
XeLaTeX inside Docker
View xelatex.sh
#!/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"