Skip to content

Instantly share code, notes, and snippets.

View gyk's full-sized avatar

Yukun Guo gyk

  • Hangzhou, China
  • 23:25 (UTC +08:00)
View GitHub Profile
(* ::Package:: *)
heron[side1_,side2_,base_]:=Module[{p,s},(
p=(side1+side2+base)/2;
s=Sqrt[p (p-side1)(p-side2)(p-base)])]
getHeight[side1_,side2_,base_]:=Module[{cos,sin,h},(
cos=(side1*side1+base*base-side2*side2)/(2*side1*base);
sin=Sqrt[1-cos*cos];
@gyk
gyk / trySAE.matlab
Created July 17, 2014 06:23
Stacked Denoising Auto-Encoder of DeepLearnToolbox (https://github.com/rasmusbergpalm/DeepLearnToolbox) - a simple example
% Playing with the Stacked Denoising Auto-Encoder in the DeepLearnToolbox
% (https://github.com/rasmusbergpalm/DeepLearnToolbox),
% and trying to use it to extract features.
%% Loads data
load mnist_uint8;
% I don't have much memory
clear test_x test_y
@gyk
gyk / generateTest.m
Last active August 29, 2015 14:05
Compute histogram of shape contexts (assuming that SC has already been calculated). Written for the stupid professor, who keeps failing at the FizzBuzz test. It may contain bugs, as most code written for the academic papers is really buggy.
% Generates test data
nPoints = 20;
nBins = 6;
nImages = 72;
shapeContexts = cell(nImages, 1);
for i = 1:nImages
sc = zeros(nPoints, nBins);
for j = 1:nPoints
% The inner matrix can be computed by double centering the
% squared distance matrix.
% This script verifies this inner matrix actually refers to the
% centroid of all points as the origin.
approxeq = @(A, B) sum(sum(abs(A - B))) < 1e-6;
nDims = 5;
n = 4;
X = rand(nDims, n);
@gyk
gyk / Haskell.sublime-build
Last active August 29, 2015 14:06
Sublime Text 2 + ghci on Windows, running Haskell script in a standalone command window
{
"cmd": ["D:\\Program Files\\Sublime Text 2.0.2\\Data\\Packages\\Haskell\\run-ghci.bat", "$file"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"shell":true,
"selector": "source.haskell"
}
@gyk
gyk / nestedDoBlocks.hs
Created September 8, 2014 06:16
Test nested do blocks in Haskell
xRange = [2, 3]
yRange = [4..6]
lComprehension = [[(x, y) | y <- yRange] | x <- xRange]
lOperator = xRange >>= (\x -> [yRange >>= \y -> [(x, y)]])
lNestedDo = do
x <- xRange
return $ do
y <- yRange
@gyk
gyk / 12321.c
Created September 17, 2014 13:52
Oneliner that counts forward and backward
#include <stdio.h>
#include <stdlib.h>
/********
func(1, 1); -> 1
func(1, 3); -> 1 2 3 2 1
func(1, 6); -> 1 2 3 4 5 6 5 4 3 2 1
`func` should be implemented without any loop, if-statement or
conditional operation.
@gyk
gyk / steps.md
Last active August 29, 2015 14:07
Installing Hakyll on Windows

In cmd.exe,

> set CABAL="D:\Program Files (x86)\Haskell Platform\2013.2.0.0\lib\extralibs\bin"
> cd %CABAL%
> cabal install hakyll
cabal: The program ghc version >=6.4 is required but it could not be found.

That didn't make sense as the Haskell Platform on this computer was newly installed:

@gyk
gyk / instructions.md
Created October 7, 2014 17:07
Compile mexw64 by VC++ 2012 & Matlab 2010b on Windows 8

Compile .mexw64 by cl.exe from VS 2012 Express for Desktop & Matlab 2010b on 64-bit Windows 8

Here is the note for how I configured Matlab to build mex C/C++ extensions on 64-bit Windows 8:
At first, mex failed to find a compiler:

>> mex -setup
Please choose your compiler for building external interface (MEX) files: 
 
Would you like mex to locate installed compilers [y]/n? y

Install OpenCV Python Binding on Windows

  1. Download OpenCV pre-built binaried from SourceForge;

  2. Set the output path of self-extracting archive to D:\Bin, and all the files will be extracted to D:\Bin\opencv;

  3. Copy cv2.pyd from %OPENCV%\build\python\2.7 to %PYTHON%\Lib\site-packages. Link in the OpenCV official site. Run Python to check whether it's been installed:

    Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
    32