Skip to content

Instantly share code, notes, and snippets.

View he9qi's full-sized avatar

Qi He he9qi

View GitHub Profile
@he9qi
he9qi / controllers.application.js
Last active July 5, 2016 06:32 — forked from poteto/controllers.application.js
ember-changeset-validations demo
import Ember from 'ember';
import AdultValidations from '../validations/adult';
import ChildValidations from '../validations/child';
const { get } = Ember;
export default Ember.Controller.extend({
AdultValidations,
ChildValidations,
actions: {
@he9qi
he9qi / relationship-helpers.js
Created March 29, 2016 04:12
Emberjs Model Relationship Test Helpers
import { test } from 'ember-qunit';
import Ember from 'ember';
export function testForHasMany(name, many) {
test('should have many ' + many, function(assert) {
const Model = this.store().modelFor(name);
const relationship = Ember.get(Model, 'relationshipsByName').get(many);
assert.equal(relationship.key, many, 'has relationship with ' + many);
assert.equal(relationship.kind, 'hasMany', 'kind of relationship is hasMany');
@he9qi
he9qi / jsonapi-helpers.js
Last active March 29, 2016 04:04
Ember Mirage JSONAPI Helpers
import Mirage/*, {faker} */ from 'ember-cli-mirage';
import Ember from 'ember';
const { isEmpty } = Ember;
export function getAllJSONAPI(config, path, type, {meta: meta, belongsTo: belongsTo} = {}) {
config.get(path, function(db/*, request*/) {
let included = [];
let relationships = null;
if (!belongsTo) { belongsTo = [];} //make sure its array
@he9qi
he9qi / ml.R
Last active August 29, 2015 14:04
Machine Learning Algorithms in R
# bagged Lasso and elastic-net regularized generalized linear models
library(foreach)
library(glmnet)
Tiqoo.bagging <- function(data.train, data.test, length_divisor=5, iterations=5000){
predictions <- foreach(m=1:iterations,.combine=cbind) %do% {
training_positions <- sample(nrow(data.train), size=floor((nrow(data.train)/length_divisor)))
train_pos <- 1:nrow(data.train) %in% training_positions
import sys
from pyspark.context import SparkContext
from numpy import array, random as np_random
from sklearn import linear_model as lm
from sklearn.base import copy
N = 10000 # Number of data points
D = 10 # Numer of dimensions
ITERATIONS = 5
#= require spec_helper
describe "Summon.PrivatePubEventsDispatcher", ->
describe "will trigger actions", ->
beforeEach ->
@controller = Ember.Object.create
queuer: {id: "1"}
trigger: ->
# After reloading the configuration file, we can send [command] to an application
# running within tmux simply by pressing [command] twice.
set -g prefix C-j
bind C-j send-prefix
unbind C-b
# Splitting panes
bind | split-window -h
bind - split-window -v
require 'digest/sha1'
require 'httparty'
require 'uri'
serverUrl = "http://api.dianping.com/"
apiPath = "v1/business/find_businesses"
appkey = "xxxxxxxxx"
secret = "xxxxxxxxxxxxxxxxxxxxxxxxxx"
param = {}
@he9qi
he9qi / server.init.sh
Created July 1, 2013 02:19
Setup ruby on server
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev git-core
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar -xvzf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125/
./configure --prefix=/usr/local
make
make install
@he9qi
he9qi / omniauth.rb
Created May 26, 2011 19:37
Set up omniauth for a social website
module SocialAppConfig
['twitter', 'renren', 'facebook', 'douban', 'tsina', 'tqq', 't163', 'kaixin', 'tsohu'].each do |auth|
raw_config = File.read("#{Rails.root}/config/providers/#{auth}.yml")
const_set "#{auth.upcase!}", YAML.load(raw_config)[Rails.env].symbolize_keys
end
end
include SocialAppConfig
Rails.application.config.middleware.use OmniAuth::Builder do