Skip to content

Instantly share code, notes, and snippets.

@rainyear
rainyear / ang2pix.js
Last active August 29, 2015 14:22
Visual Angle.
// cal Pix size with given visual angle and screen info.
var scr = {
xpixels: 1024,
ypixels: 768,
width: 360, //mm
height: 270, //mm
}
var ang2pix = function(screen, angle, distense){
var targetWidth = angle.h * distense / (180 / 3.14);
@rainyear
rainyear / Hspell.hs
Last active November 7, 2015 08:19
Spell corrector
import Data.Char (toLower)
import qualified Data.Map as Map -- (insertWith, empty, member)
import qualified Data.Set as Set -- (fromList, toList, union, unions)
main :: IO ()
main = do
fileStr <- readFile "big.txt"
let training = words $ toLower <$> fileStr
let knowledge = foldl (\m word -> Map.insertWith (+) word 1 m) Map.empty training
@rainyear
rainyear / ghost_foot.html
Last active November 15, 2015 05:37
http://blog.rainy.im is using ghost, {{ghost_foot}} injection was used to append donate button to every article.
<script type='tmpl' class='donation'>
<pre>
<code class="language-javascript">
if(post.content.isHelpful){
$("button#donate").click();
};
</code>
</pre>
<button
type="button"
@rainyear
rainyear / find_file_type_counts.sh
Last active December 18, 2015 07:19
find out how many files of specific type are there in current project.
find . -type f -name *.java | wc
;.inputrc
set completion-ignore-case on
;.screenrc
startup_message off
hardstatus on
hardstatus alwayslastline
hardstatus string "%{.bW}%-w%{.rY}%n %t%{-}%+w %=%{..G} %H(%l) %{..Y} %Y/%m/%d %c:%s "
@rainyear
rainyear / javar.sh
Created June 24, 2013 05:44
compile and run java script
[ -f "$1.class" ] && rm $1.class
for file in $1.java
do
echo "Compiling $file........"
javac $file
done
if [ -f "$1.class" ]
then
echo "-----------OUTPUT-----------"
java $1
@rainyear
rainyear / x.sublime-build
Last active December 18, 2015 21:29
compile & run scripts in sublime text.
//Java.sublime-build
{
"cmd": ["javac", "$file"],
"selector": "source.java",
"encoding": "cp936",
"variants":
[{
"name": "Run",
"cmd": ["java", "$file_base_name"]
}]
#!/usr/bin/python
from distutils.sysconfig import get_python_lib
print get_python_lib()
@rainyear
rainyear / root_android.sh
Last active December 19, 2015 08:19
root android emulator 4.2.2
cd adt-X/sdk/platform-tools/
./adb shell
mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
cd /system/bin
# try
cat sh > su
@rainyear
rainyear / diag
Created July 15, 2013 08:50
usb-debug xiaomi with eclipse
*#*#717717#*#*