Skip to content

Instantly share code, notes, and snippets.

View otobrglez's full-sized avatar
🏗️
Building.

Oto Brglez otobrglez

🏗️
Building.
View GitHub Profile
@gvolpe
gvolpe / parTraverseN.scala
Last active February 15, 2024 15:29
parTraverse with a limit of N using a Semaphore
import cats.Traverse
import cats.effect._
import cats.effect.concurrent.Semaphore
import cats.temp.par._
import cats.syntax.all._
import scala.concurrent.duration._
object Main extends IOApp {
import ParTask._
akar.try-out=> (macroexpand-1 '(match n
(:and [(!div-by 3)][(!div-by 5)]) "Fizzbuzz"
[(!div-by 3)] "Fizz"
[(!div-by 5)] "Buzz"
:_ n))
(akar.primitives/match* n
(akar.primitives/or-else
(akar.primitives/clause* (akar.combinators/!and (!div-by 3) (!div-by 5)) (clojure.core/fn [] "Fizzbuzz"))
(akar.primitives/clause* (!div-by 3) (clojure.core/fn [] "Fizz"))
@ruslanbogun
ruslanbogun / gist:0cd5b91cc80bd8346273e0be966fa588
Last active August 8, 2019 13:55
No implicit Ordering defined for org.joda.time.DateTime
implicit def dateTimeOrdering: Ordering[DateTime] = Ordering.fromLessThan(_ isBefore _)
@otobrglez
otobrglez / RegressionApp.scala
Last active September 11, 2018 17:14
Linear regression with pure 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
@nicolasembleton
nicolasembleton / restart_bluetooth.sh
Last active October 21, 2022 20:10
Restart Bluetooth Daemon on Mac OS X without restarting
#!/bin/bash
sudo kextunload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
sudo kextload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
@KrofDrakula
KrofDrakula / gist:5261852
Last active December 15, 2015 12:39
Dobil vprašanje na LinkedIn za začetnike programiranja, pa sem se odločil napisati daljši odgovor, ker pogosto prejemam podobna vprašanja.

Vprašanje:

Zdravo,

Sem rekel, da se bom kar na tebe obrnil, ker si mi zdiš najbolj primeren za to vprašanje.

Sem mal pregledal zadevo in sedaj imam sledeči spisek:

  • Ruby
  • Java
@joho
joho / gzip_net_http.rb
Created September 19, 2012 04:12
Handling gzip responses in Ruby Net::HTTP library
# from http://pushandpop.blogspot.com.au/2011/05/handling-gzip-responses-in-ruby-nethttp.html
# i wanted syntax highlighting
require 'net/http'
debug = Proc.new{|msg| STDERR.puts "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}] #{msg}" }
page = nil
http = Net::HTTP.new( "www.google.com", 80 )
req = Net::HTTP::Get.new( "/search?num=20&hl=en&noj=1&q=test&btnG=Search", { "Accept-Encoding" => "gzip", "User-Agent" => "gzip" } )
@josevalim
josevalim / 0_README.md
Created September 13, 2012 21:52
Sinatra like routes in Rails controllers

Sinatra like routes in Rails controllers

A proof of concept of having Sinatra like routes inside your controllers.

How to use

Since the router is gone, feel free to remove config/routes.rb. Then add the file below to lib/action_controller/inline_routes.rb inside your app.

@scttnlsn
scttnlsn / README.md
Created July 30, 2012 22:16
Pub/sub with MongoDB and Node.js

Pub/sub with MongoDB and Node.js

Setup:

$ mongo
> use pubsub
> db.createCollection('messages', { capped: true, size: 100000 })
> db.messages.insert({})
@otobrglez
otobrglez / car.rb
Created August 23, 2011 12:26
Experimenting with observer pattern (publish/subscribe pattern) in Ruby
# 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