Skip to content

Instantly share code, notes, and snippets.

View xixilive's full-sized avatar
🌴
On vacation

xixilive xixilive

🌴
On vacation
View GitHub Profile
@xixilive
xixilive / setup_android_keystore.js
Last active May 9, 2016 20:31
Setup Android Keystore after android platform added in Ionic/Cordova project
#!/usr/bin/env node
/**
* Setup android keystore
* Save this script in hooks/after_paltform_add/
* And make sure it has x permission
*/
var exec = require('child_process').exec;
var path = require('path');
@xixilive
xixilive / findup_or_create.rb
Last active August 29, 2015 14:10
Mongoid find and update, or create
# === Example
# class User
# include Mongoid::Document
# extend FindupOrCreate
#
# field :name, type: String
# field :locale, type: String
# field :password,type: String
# end
#
@xixilive
xixilive / routing_marcors.rb
Last active August 29, 2015 14:00
Restful routing spec macor
module RoutingMacors
CRUD = { index: :get, show: :get, new: :get, edit: :get, update: :put, create: :post, destroy: :delete }
def have_restful_resource *resources
faked_id = Time.now.to_i.to_s
options = resources.extract_options!
collection_name = resources.last.to_s.pluralize
ancestors = resources[0..-2].collect{|ancestor| [ancestor.to_s.pluralize, faked_id] }.join("/")
actions = CRUD.keys
@xixilive
xixilive / devise.zh-CN.yml
Created April 14, 2014 10:40
devise.3.1.2 i18n zh-CN
zh-CN:
devise:
helpers:
labels:
username_placeholder: "用户名/手机号码/电子邮件"
email_placeholder: "电子邮件"
mobile_placeholder: "手机号码"
password_placeholder: "密码"
password_conformation_placeholder: "确认密码"
@xixilive
xixilive / gist:9502333
Created March 12, 2014 07:24
Sublime2 Package Controll install script
import urllib2,os;pf='Package Control.sublime-package';ipp=sublime.installed_packages_path();os.makedirs(ipp) if not os.path.exists(ipp) else None;open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read())
@xixilive
xixilive / gist:9478656
Created March 11, 2014 02:53
Mongoid Utils
module MongoidUtils
module RandomDocuments
extend ActiveSupport::Concern
module ClassMethods
def random n = 1
skip((rand * 99999999).to_i % ([count-n, 2].max)).limit(n)
end
end
end
Summarizer(originalText, maxSummarySize):
    // 计算原始文本的词频,生成一个数组,比如[(10,'the'), (3,'language'), (8,'code')...]
    wordFrequences = getWordCounts(originalText)
    // 过滤掉停用词,数组变成[(3, 'language'), (8, 'code')...]
    contentWordFrequences = filtStopWords(wordFrequences)
    // 按照词频进行排序,数组变成['code', 'language'...]
    contentWordsSortbyFreq = sortByFreqThenDropFreq(contentWordFrequences)
    // 将文章分成句子
    sentences = getSentences(originalText)
    // 选择关键词首先出现的句子
@xixilive
xixilive / gist:6934626
Created October 11, 2013 13:25
Install sublime text2 in ubuntu via apt-get
sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text-2
@xixilive
xixilive / random_selector.rb
Created July 3, 2012 03:27
RandomSelector for ActiveModel via Mongoid
module RandomSelector
class << self
def included(base)
base.module_eval do
def self.random n, conditions=nil
criteria = conditions.is_a?(Mongoid::Criteria) ? (self.where({}).merge(conditions)) : self.where(conditions||{})
cc = criteria.count
mo = [cc-n,2].max
criteria.skip((rand*cc%mo).to_i).limit(n)
end
@xixilive
xixilive / pinyin.php
Created May 4, 2012 15:06
get Chinese Pinyin
<?php
/**
* StringUtil
*
* @author mickey
* @version 1.0
* @package Utility
*/
final class StringUtil
{