Skip to content

Instantly share code, notes, and snippets.

View johnykov's full-sized avatar

Jan Kowalski johnykov

View GitHub Profile
@johnykov
johnykov / blogs.md
Last active July 5, 2023 10:44
pages
@johnykov
johnykov / ruby_book_author.rb
Last active September 23, 2022 11:59
ruby_book_author
class Book
attr_reader :title, :authors, :published_at
def initialize(title, authors, published_at)
@title = title
@authors = authors
@published_at = published_at
end
end
@johnykov
johnykov / angular.test.js
Last active January 18, 2018 08:43
mocha, chai, sinon
describe('should navigate repeated customer ', () => {
let scope, ctrl, state, rootScope, fakeProfileService, sandbox, $provide, $controller;
beforeEach(module('rootApp'));
afterEach(() => sandbox.restore());
beforeEach(() => module('rootApp', function(_$provide_) {
$provide = _$provide_;
@johnykov
johnykov / Recommender.scala
Last active July 13, 2017 17:49
My non-blocking scala recommender, searching through database for cheaper merchant, scala, slick
class Recommender(transactionModel: SasquatchTransactionModel)(implicit ec: ExecutionContext) extends StrictLogging {
def findCheaperMerchant(transaction: SasquatchTransactionDTO): DBRead[Seq[SasquatchRecommendation]] = {
val mId: String = transaction.merchantId
logger.info(s"Computing cheaper merchant for transaction: ${transaction.extId} merchant: ${mId}")
val top10NearestMerchants = transactionModel.nearestNeighbour(
long = transaction.long,
lat = transaction.lat,
category = transaction.category
@johnykov
johnykov / ActorDSLfromREPL
Last active August 29, 2015 14:24
ActorDSL helps to provision actor to test in repl. For this example to work you need `build.sbt` file with akka dependency as stated here http://doc.akka.io/docs/akka/snapshot/intro/getting-started.html and type `sbt console` in same directory.
import akka.actor.ActorDSL._
import akka.actor.ActorSystem
// need an actor system, make it implicit to it's used by all our repl based actors
implicit val system = ActorSystem("demo")
// here's a simple example of creating an actor
// Also, this will give us a simple actor that is used to print the
// results sent back to us from the other actors.
val a = actor(new Act {
@johnykov
johnykov / MyJsonProtocol.scala
Last active August 29, 2015 14:13
This is my class parsing special fuckeup JSONs where instead `"key":numericValue` I get `"key":"numericValue"`. I use https://github.com/spray/spray-json
import spray.json._
object MyJsonProtocol extends DefaultJsonProtocol {
implicit object MetricJsonFormatDouble extends RootJsonFormat[Metric[Double]] {
def write(c: Metric[Double]) = JsObject()
def read(value: JsValue) = value.asJsObject.getFields("total", "ok", "ko") match {
case Seq(JsString(total), JsString(ok), JsString(ko)) =>
Metric[Double](total.toDouble, ok.toDouble, ko.replace("-", "0").toDouble)
@johnykov
johnykov / ruby_jekyll
Created May 22, 2014 09:05
Step-by-step install jekyll on mac
1.
brew install ruby
brew info ruby
2.
#Add this line to your .profile (or .bash_profile, .bashrc, .zshrc, etc):
export PATH=/usr/local/opt/ruby/bin:$PATH
#restart terminal
3.
gem install jekyll
@johnykov
johnykov / docker_mongo_macosx
Created May 21, 2014 11:44
Step-by-step mongo in docker on macosx
1.
brew install boot2docker
brew install docker
echo "export DOCKER_HOST=tcp://127.0.0.1:4243" >>~/.bash_profile
2.
boot2docker init #once init virtualbox vm
VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port$27017,tcp,,27017,,27017";
3.
@johnykov
johnykov / 0_reuse_code.js
Created April 29, 2014 21:50
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@johnykov
johnykov / heroku_bottle_python
Created March 23, 2013 09:04 — forked from defnull/gist:1224387
Quick tutorial how to deploy on heroku a python bottle app
mkdir heroku
cd heroku/
virtualenv --no-site-packages env
source env/bin/activate
pip install bottle gevent
pip freeze > requirements.txt
cat >app.py <<EOF
import bottle
import os