Skip to content

Instantly share code, notes, and snippets.

rnd_permu :: [a] -> IO [a]
rnd_permu xs = do
arr <- A.newListArray (1,l) xs
forM [1..l] $ \i -> do
j <- randomRIO (1, i)
vi <- (A.readArray arr i)
vj <- (A.readArray arr j)
A.writeArray arr j vi
A.writeArray arr i vj
pure vj
@hvariant
hvariant / convert.hs
Last active October 21, 2019 13:18
convert a C struct to Rust struct, incomplete and probably wrong but works 100% some of the time
import Language.C
import Language.C.System.GCC
import Language.C.Data.Ident
import Language.C.Syntax.AST
import Control.Monad
import Data.Char
import Data.Void
use async_std::sync::{Arc, Mutex};
use serde::{Deserialize, Serialize};
use tide::{response, Context, EndpointResult};
#[derive(Serialize, Deserialize, Clone)]
struct Message {
author: Option<String>,
contents: String,
}
set nocp nobk "nocompatible and nobackup
set bs=2 ts=2 sw=2 et ai si
set ic is "ignore case and incsearch
set nu cuc cul ls=2 ru
syntax on
filetype plugin indent on
colo desert "to see all color schemes type :colo <C-d>
@hvariant
hvariant / io_sync_off.cpp
Created December 30, 2018 13:19
Leetcode speedup trick
static const auto io_sync_off = []()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
return nullptr;
}();
@hvariant
hvariant / tmux_local_install.sh
Created August 21, 2017 14:24 — forked from ryin/tmux_local_install.sh
bash script for installing tmux without root access
#!/bin/bash
# Script for installing tmux on systems where you don't have root access.
# tmux will be installed in $HOME/local/bin.
# It's assumed that wget and a C/C++ compiler are installed.
# exit on error
set -e
TMUX_VERSION=1.8
@hvariant
hvariant / gist:dd54bcb1efb12ab4dba94acfd87c4db5
Last active June 8, 2017 08:53
comparing Eric's AVL tree with TreeSet
int N = 10000;
double start = System.currentTimeMillis();
bt = new AvlEmptyBinaryTree();
for (int i = 0; i < N; i++) bt = bt.insert(i);
System.out.println((System.currentTimeMillis() - start)/1000.0);
start = System.currentTimeMillis();
TreeSet<Integer> ts = new TreeSet<>();
for(int i=0;i<N;i++) ts.add(i);
@hvariant
hvariant / schedule.txt
Created April 29, 2017 09:49
comp6442 Monday workshop&lab schedule
lab workshop
Week9: lab4 activity9
Week10: lab5 activity10 (quiz5)
Week11: activity7 activity11
Week12: lab6 activity12 (quiz6)
#!/bin/bash
for i in $1/*.webm;
do name=`echo $i | cut -d'.' -f1`;
echo $name;
ffmpeg -i $i $name.mp4;
done
12330001 Alipu`Wupuer
12330009 caolei
12330019 陈家炜
12330024 ?
12330033 chenweifang
12330035 chenwei
12330040 陈雄涛
12330041 陈秀
12330043 陈雅雪
12330044 chenyaying