Skip to content

Instantly share code, notes, and snippets.

@lengshuiyulangcn
lengshuiyulangcn / compile_uplatex.sh
Created November 13, 2014 12:51
quick compile&show preview of uplatex
#!bin/sh
uplatex $1 && dvipdfmx -f cid-x.map $1 && open -a Preview "$1.pdf"
p =->(x){x**2}
#call with p.call(x) or p.(x)
#define 1377 classes with different names and each has one class method with different names and one instance methtod with different names
def leet_classes
(1..1337).to_a.map do |i|
Object.const_set("FooBar_#{i}", Class.new {
define_singleton_method("class_method_#{i}") { "class_method_value_#{i}" }
define_method("instance_method_#{i}") { "instance_method_value_#{i}" }
})
end
end
@lengshuiyulangcn
lengshuiyulangcn / shuffle.js
Created November 21, 2014 11:29
Array#shuffle in js
//Array#shuffle
Array.prototype.shuffle = function() {
var i = this.length;
while(i){
var j = Math.floor(Math.random()*i);
var t = this[--i];
this[i] = this[j];
this[j] = t;
}
return this;
@lengshuiyulangcn
lengshuiyulangcn / NLPIR.h
Created December 4, 2014 11:35
swig and head file for nlpir
/****************************************************************************
*
* NLPIR/ICTCLAS Lexical Analysis System Copyright (c) 2000-2014
* Dr. Kevin Zhang (Hua-Ping Zhang)
* All rights reserved.
*
* This file is the confidential and proprietary property of
* Kevin Zhang and the possession or use of this file requires
* a written license from the author.
* Filename:
@lengshuiyulangcn
lengshuiyulangcn / latex_author
Created January 19, 2015 11:57
Latex 著者と所属がn対mの場合
\usepackage{authblk}
\makeatletter
\renewcommand{\AB@affilsep}{\quad\protect\Affilfont}
\let\AB@affilsepx\AB@affilsep % 所属間の改行を無効化
\renewcommand\Authands{\quad}
\renewcommand\Authsep{\quad}
\makeatother
\author[1]{aa}
\author[1,2]{bb}
@lengshuiyulangcn
lengshuiyulangcn / rails_lightbox2
Created February 7, 2015 16:40
use lightbox2 with rails4 on view
<!--
light box with rails4
!-->
<%= link_to image_tag(image.thumb), image.url, :'data-lightbox' => image.id %>
@lengshuiyulangcn
lengshuiyulangcn / has_and_belongs_to_many_strong_parameters.rb
Last active August 29, 2015 14:15
rails4 strong parameters, has_and_belongs_to_many relation, mongoid
#model
class Band
include Mongoid::Document
has_and_belongs_to_many :tags
end
class Tag
include Mongoid::Document
field :name, type: String
has_and_belongs_to_many :bands
@lengshuiyulangcn
lengshuiyulangcn / parse_torrent.rb
Created February 14, 2015 13:41
a script for parsing adult video torrents
# usage:
# ruby parse_torrent.rb keyword page_numbers
require "mechanize"
agent=Mechanize.new
term=ARGV[0]
offset=0
offset=ARGV[1].to_i if ARGV[1]!=nil
torrent_links=[]
for i in 0..offset
@lengshuiyulangcn
lengshuiyulangcn / proxy.rb
Last active August 29, 2015 14:15 — forked from torsten/proxy.rb
#!/usr/bin/env ruby
# A quick and dirty implementation of an HTTP proxy server in Ruby
# because I did not want to install anything.
#
# Copyright (C) 2009-2014 Torsten Becker <torsten.becker@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,