Skip to content

Instantly share code, notes, and snippets.

View robertsosinski's full-sized avatar

Robert Sosinski robertsosinski

View GitHub Profile
@robertsosinski
robertsosinski / gist:62abbac4eacda6548be1
Last active May 7, 2021 01:11
Recursive Factorial and Fibonacci in Different Languages
def fac(n: Int): BigInt = n match {
case 0 => 1
case _ => n * fac(n - 1)
}
def facTail(n: Int, acc: BigInt = 1): BigInt = n match {
case 0 => acc
case _ => facTail(n - 1, n * acc)
}
@robertsosinski
robertsosinski / Notifier.scala
Created May 20, 2014 20:21
Listening to Asynchronous Listen/Notify with Scala and Akka
package io.reactive.sandbox.actors
import java.sql.DriverManager
import org.postgresql.PGConnection
import akka.actor.{Actor, ActorLogging, ActorRef}
case class Subscription(channel: String)
case class UnSubscription(channel: String)
@robertsosinski
robertsosinski / factorial.go
Last active August 29, 2015 14:01
Computing Factorials in Parallel in Go
package main
import (
"fmt"
"math/big"
"runtime"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
@robertsosinski
robertsosinski / .jshintrc
Last active August 29, 2015 14:00
My JSHint Options
{
"browser": true, // specifies globals exposed by modern browsers
"strict": true, // specifies that restricted JavaScript is used
"indent": 2, // indentation should consistently be 2 spaces
"nonew": true, // prevents using constructers for side effects
"noarg": true, // prevents using deprecated caller,callee methods
"eqeqeq": true, // prevents equality == and != operators from being used
"bitwise": true, // prevents bitwise & and | operators from being used
@robertsosinski
robertsosinski / Factorial.scala
Created April 7, 2014 05:37
Generating factorial numbers with parallel processing using Akka
import akka.actor.{Actor, ActorLogging, ActorSystem, Props}
object Factorial extends App {
val factorials = List(200000, 180000, 320000, 280000, 220000, 420000, 550000, 480000)
val system = ActorSystem("factorial")
val collector = system.actorOf(Props(new FactorialCollector(factorials)), "fac-coll")
system.awaitTermination()
@robertsosinski
robertsosinski / .bash_profile
Created December 12, 2013 04:45
Git Prompt
# Git Prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (.*\)/(\1)/'
}
export PS1="\u@\h \W\$(parse_git_branch)$ "
@robertsosinski
robertsosinski / postgresql.py
Last active June 25, 2020 10:32
DataDog script for collecting PostgreSQL stats
# Create the datadog user with select only permissions:
# CREATE USER datadog WITH PASSWORD '<complex_password>';
#
# Grant select permissions on a table or view that you want to monitor:
# GRANT SELECT ON <schema>.<table> TO datadog;
#
# Grant permissions for a specific column on a table or view that you want to monitor:
# GRANT SELECT (id, name) ON <schema>.<table> TO datadog;
#
# Let non-superusers look at pg_stat_activity in a read-only fashon.
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="[\t] \u@\h:\W\$(parse_git_branch)$ "
@robertsosinski
robertsosinski / gist:5605881
Last active December 17, 2015 11:58
Additional logic operators for PostgreSQL
CREATE FUNCTION xor(bool, bool) RETURNS bool AS 'SELECT ($1 AND NOT $2) OR (NOT $1 AND $2);' LANGUAGE 'sql';
CREATE OPERATOR ~| (PROCEDURE='xor', LEFTARG=bool, RIGHTARG=bool);
CREATE FUNCTION condition(bool, bool) RETURNS bool AS 'SELECT CASE WHEN $1 AND NOT $2 THEN false ELSE true END;' LANGUAGE 'sql';
CREATE OPERATOR -> (PROCEDURE='condition', LEFTARG=bool, RIGHTARG=bool);
CREATE FUNCTION bicondition(bool, bool) RETURNS bool AS 'SELECT CASE WHEN ($1 AND $2) OR (NOT $1 and NOT $2) THEN true ELSE false END;' LANGUAGE 'sql';
CREATE OPERATOR <-> (PROCEDURE='bicondition', LEFTARG=bool, RIGHTARG=bool);
@robertsosinski
robertsosinski / example.txt
Created January 19, 2013 03:13
Sequel model plugin that makes faceting easy.
ProductType.facet(:name).all
[{:name=>"Direct Receiver", :count=>9},
{:name=>"Input System", :count=>6},
{:name=>"Performance Compressor", :count=>6},
{:name=>"Air Controller", :count=>5},
{:name=>"Audible Mount", :count=>5},
{:name=>"Auto Amplifier", :count=>5},
{:name=>"Digital Component", :count=>5},
{:name=>"Direct Transmitter", :count=>5},
{:name=>"Gel Receiver", :count=>5}...