Skip to content

Instantly share code, notes, and snippets.

Avatar

Artem Yankov yankov

View GitHub Profile
View gist:2485964
require 'rubygems'
require 'redis'
require 'redis/distributed'
r = Redis::Distributed.new %w[redis://host1:6379 redis://host2:6379]
# show node for key "foo"
p r.node_for("foo")
# set the value of "foo"
View gist:c2ec3864c963da3b59f6
# Avazu CTR prediction
# SGD Logistic regression + one hot encoder. Score: 0.414
import pandas as pd
import numpy as np
from datetime import datetime, date, time
from OneHotEncoderPartial import OneHotEncoder
from sklearn.linear_model import SGDClassifier
cols = ["C1","banner_pos","site_category", "device_type","device_conn_type","C14","C15","C16","C17","C18","C19","C20","C21", "hour"]
View gist:1ab961c108613cf2d63a
# Avazu CTR prediction
# SGD Logistic regression + hashing trick.
import pandas as pd
import numpy as np
from datetime import datetime, date, time
from sklearn.linear_model import SGDClassifier
from sklearn.feature_extraction import FeatureHasher
from sklearn.preprocessing import LabelEncoder
View gist:a86d44bf0e6009944c21
from scipy import sparse
class OneHotEncoder():
"""
OneHotEncoder takes data matrix with categorical columns and
converts it to a sparse binary matrix doing one-of-k encoding.
Parts of code borrowed from Paul Duan (www.paulduan.com)
Licence: MIT (https://github.com/pyduan/amazonaccess/blob/master/MIT-LICENSE)
@yankov
yankov / gist:7646128
Last active Dec 29, 2015
cassandra test
View gist:7646128
import com.datastax.driver.core._
val cluster = Cluster.builder.addContactPoint("127.0.0.1").build
val session = cluster.connect
// http://www.datastax.com/documentation/developer/java-driver/1.0/webhelp/index.html#java-driver/quick_start/qsSimpleClientAddSession_t.html
session.execute("CREATE KEYSPACE simplex WITH replication " +
"= {'class':'SimpleStrategy', 'replication_factor':3};");
session.execute(
@yankov
yankov / gist:5843404
Created Jun 23, 2013
producer example
View gist:5843404
val topic = "urls"
val props = new Properties()
props.put("broker.list", "0:localhost:9092")
props.put("serializer.class", "kafka.serializer.StringEncoder")
val config = new ProducerConfig(props)
val producer = new Producer[String, String](config)
val data = new ProducerData[String, String](topic, href)
producer.send(data)
@yankov
yankov / gist:5538283
Created May 8, 2013
Water pouring problem solution from Odersky's course
View gist:5538283
package week7
class Pouring(capacity: Vector[Int]) {
// States
type State = Vector[Int]
val initialState = capacity map (x => 0)
// Moves
@yankov
yankov / gist:4230948
Last active Oct 13, 2015
Creating new Scala project with sbt
View gist:4230948
mkdir project1
cd project1
sbt
set name := "project1"
set version := "1.0"
set scalaVersion := "2.9.3"
session save
exit
View gist:3886363
a = new A();
b = new a.B();
// how in 'b' have a refference to 'a'?
View gist:3881879
function A(name) {
this.name = name;
}
A.prototype.b = function(lastName) {
this.lastName = lastName;
console.log(this.name + " " + this.lastName);
}
a1 = new A("Howard");