Skip to content

Instantly share code, notes, and snippets.

View ilovejs's full-sized avatar
🐡

Hao ilovejs

🐡
  • 08:50 (UTC +10:00)
View GitHub Profile
# This method finds related articles using Jaccard index (optimized for PostgreSQL).
# More info: http://en.wikipedia.org/wiki/Jaccard_index
class Article < ActiveRecord::Base
def related(limit=10)
Article.find_by_sql(%Q{
SELECT
a.*,
( SELECT array_agg(t.name) FROM taggings tg, tags t
@ilovejs
ilovejs / install-nodejs.txt
Created March 28, 2014 03:15
install node.js on ubuntu
Method 1:
download node-xxx.gz on http://nodejs.org/
//extract file
tar -xf node-xxx.gz
(ps: compression can be done):
tar -cf node.gz folder1 folder2

Movie Recommendations with k-Nearest Neighbors and Cosine Similarity


Introduction

The k-nearest neighbors (k-NN) algorithm is among the simplest algorithms in the data mining field. Distances / similarities are calculated between each element in the data set using some distance / similarity metric ^[1]^ that the researcher chooses (there are many distance / similarity metrics), where the distance / similarity between any two elements is calculated based on the two elements' attributes. A data element’s k-NN are the k closest data elements according to this distance / similarity.


1. A distance metric measures distance; the higher the distance the further apart the neighbors. A similarity metric measures similarity; the higher the similarity the closer the neighbors.
http://installrails.com/steps/choose_os
SQLManagementStudio_x64_ENU
@ilovejs
ilovejs / mlr.r
Created April 23, 2014 08:31
Machine learning in r
> m <- matrix(c('a', 'b', 'c', 'd'), ncol = 2)
> save(x, y, z, file = "mydata.RData")
> load("mydata.RData")
//read in
> pt_data <- read.csv("pt_data.csv", stringsAsFactors = FALSE)
> mydata <- read.csv("mydata.csv", stringsAsFactors = FALSE,
@ilovejs
ilovejs / T4TS.tt
Created April 24, 2014 02:38 — forked from alexdresko/T4TS.tt
<#@ template language="C#" debug="true" hostspecific="true" #>
<#@ output extension=".d.ts" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="Microsoft.VisualStudio.Shell.Interop.8.0" #>
<#@ assembly name="EnvDTE" #>
<#@ assembly name="EnvDTE80" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="EnvDTE" #>
Array.prototype.mergeSort=function(){
var merge=function(left,right){
var final=[];
while (left.length && right.length) {
final.push(left[0] <= right[0] ? left.shift() : right.shift() );
}
return final.concat(left.concat(right));
}
// 递归结束
if (this.length < 2) {
//Orderby, Split
string[] musos = { "Roger Waters", "David Gilmour", "Rick Wright", "Nick Mason" };
musos.OrderBy (m => m.Split().Last()) .Dump ("Sorted by last name");
//6.5: Fetch books using LINQ to SQL
//LINQPad abstracts the context. We'll set it to this.
DataContext dataContext = this;
IQueryable<Book> query = from book in dataContext.GetTable<Book>()
http://devstreaming.apple.com/videos/wwdc/2014/403xxksrj0qs8c0/403/403_hd_intermediate_swift.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/403xxksrj0qs8c0/403/403_sd_intermediate_swift.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/403xxksrj0qs8c0/403/403_intermediate_swift.pdf?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/419xxli6f60a6bs/419/419_hd_advanced_graphics_and_animation_performance.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/419xxli6f60a6bs/419/419_sd_advanced_graphics_and_animation_performance.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/419xxli6f60a6bs/419/419_advanced_graphics_and_animation_performance.pdf?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/101xx36lr6smzjo/101/101_hd.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/101xx36lr6smzjo/101/101_sd.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/236xxwk3fv82sx2/236/236_hd_building_interruptible_and_responsive_interactions.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2