Skip to content

Instantly share code, notes, and snippets.

Avatar
🏗️
Building.

Oto Brglez otobrglez

🏗️
Building.
View GitHub Profile
@otobrglez
otobrglez / jaccard_recommendation.rb
Last active Aug 7, 2020
Simple recommendation system written in Ruby based on Jaccard index.
View jaccard_recommendation.rb
# Simple Recommendation Engine in Ruby
# Visit: http://otobrglez.opalab.com
# Author: Oto Brglez <otobrglez@gmail.com>
class Book < Struct.new(:title)
def words
@words ||= self.title.gsub(/[a-zA-Z]{3,}/).map(&:downcase).uniq.sort
end
@otobrglez
otobrglez / Article.rb
Created Jul 12, 2011
Finding related articles using Jaccard index and tags
View Article.rb
# 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
@otobrglez
otobrglez / NodeApp.scala
Last active Jul 9, 2020
Simple Akka Cluster with decline and Akka Typed.
View NodeApp.scala
/**
* Author: Oto Brglez - <otobrglez@gmail.com>
*/
package com.pinkstack.realestate.clustering4
import akka.actor.typed._
import akka.actor.typed.scaladsl._
import akka.cluster.ClusterEvent.MemberEvent
import akka.cluster.typed._
import com.monovore.decline._
@otobrglez
otobrglez / casting_types.rb
Created Mar 12, 2015
unknown OID 705: failed to recognize type of '<field>'. It will be treated as String.
View casting_types.rb
#!/usr/bin/env ruby
# If you get "unknown OID 705: failed to recognize type of '<field>'. It will be treated as String."
# it probably means that type of column could not be identified when retriving records
# Example
User.where("'something' as something")
# Will results in unknown OID. However doing this:
View adb-completion.bash
# /* vim: set ai ts=4 ft=sh: */
#
# Copyright 2011, The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@otobrglez
otobrglez / yaml_to_json.sh
Created Jun 3, 2016
YAML to JSON - one-liner with Ruby
View yaml_to_json.sh
# Single line of Ruby <3.
ruby -rjson -ryaml -e "puts YAML.load_file('my_file.yml').to_json"
# You can also pipe it to Python to get pretty ouput
ruby -rjson -ryaml -e "puts YAML.load_file('my_file.yml').to_json" | \
python -mjson.tool
# Thats all. :)
View Boot5.scala
package com.examples.streaming_one
import akka.Done
import akka.actor.ActorSystem
import akka.stream._
import akka.stream.scaladsl._
import slick.jdbc.JdbcBackend.Database
import slick.jdbc.PostgresProfile.api._
import slick.jdbc.{ResultSetConcurrency, ResultSetType}
@otobrglez
otobrglez / as3.rake
Created Jun 29, 2011
Rake task for uploading Rails 3.1 compiled assets to Amazon S3 storage
View as3.rake
# 1) Put 's3' gem in Gemfile.
# 2) Create as3.yml configuration for S3
# 3) Create initializer for as3.yml
# 4) Make "assets" folder inside your bucket
# 5) After running task run "RAILS_ENV=production rake assets:precompile"
# 6) Invoke task by running "rake as3:upload"
namespace :as3 do
desc "Uploads compiled assets (public/assets) to Amazone AS3"
task :upload do
@otobrglez
otobrglez / car.rb
Created Aug 23, 2011
Experimenting with observer pattern (publish/subscribe pattern) in Ruby
View car.rb
# Simple Car class. Nothing special here...
class Car
attr_accessor :brand
attr_accessor :model
attr_accessor :year
def initialize(brand, model, year=2011)
@brand, @model, @year = brand, model, year
end
@otobrglez
otobrglez / RegressionApp.scala
Last active Sep 11, 2018
Linear regression with pure Scala
View RegressionApp.scala
import scala.math.{pow}
import scala.concurrent._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.collection.mutable.ArrayBuffer
object Regression {
def linear(pairs: IndexedSeq[Seq[Double]]) = {
val n = pairs.size
You can’t perform that action at this time.