Skip to content

Instantly share code, notes, and snippets.

View ilovejs's full-sized avatar
🐡
mememe, hv a good fish !

Michael Zhuang ilovejs

🐡
mememe, hv a good fish !
  • Sydney
  • 23:49 (UTC +10:00)
View GitHub Profile
@ilovejs
ilovejs / BrowserDetect.js
Created February 5, 2014 00:06
detect browser
/*
BrowserDetect.browser == 'Explorer';
BrowserDetect.version <= 8;
*/
var BrowserDetect =
{
init: function () {
this.browser = this.searchString(this.dataBrowser) || "Other";
this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "Unknown";
},
@ilovejs
ilovejs / global.R
Created February 15, 2014 02:44 — forked from hrbrmstr/global.R
library(shiny)
library(ggplot2)
library(RCurl)
library(reshape2)
(loop [i 0]
(if (< i 10)
(recur (inc 1))
i))
(str "2 is " (if (even? 2) "even" "odd"))
(if (true? false) "impossible!")
(defn factorial [x]
@ilovejs
ilovejs / Install Lein
Last active August 29, 2015 13:57
Installation Leiningen
//remove lein
rm -r ~/.m2
echo $PATH
ls /usr/bin | grep lein
...
rm -r /usr/bin/lein
//install lein
wget https://raw.github.com/technomancy/leiningen/stable/bin/lein
sudo mv lein /usr/bin/lein
$ sudo apt-get remove mplayer
$ sudo apt-get --purge remove lighttpd
//To list all installed package
dpkg --list
dpkg --list | less
dpkg --list | grep -i 'http'
#!/usr/bin/env ruby
# Please read http://otobrglez.opalab.com for more information about this code.
class Book < Struct.new(:title)
def words
@words ||= self.title.gsub(/[a-zA-Z]{3,}/).map(&:downcase).uniq.sort
end
# 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