Skip to content

Instantly share code, notes, and snippets.

View robertsosinski's full-sized avatar

Robert Sosinski robertsosinski

View GitHub Profile
@robertsosinski
robertsosinski / SSHKeyRole
Last active July 5, 2017 22:01
Use AWS IAM for ssh key management
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iam:GetSSHPublicKey",
"iam:ListSSHPublicKeys"
],
"Resource": [
@robertsosinski
robertsosinski / dice.ex
Last active January 5, 2017 00:53
Functional Dice Rolling
defmodule Dice do
def sum_probability(dice, target) do
prob = :math.pow(6, dice) |> round
total = 6 * dice
"#{sum_probability(dice, target, total)} / #{prob}"
end
defp sum_probability(dice, target, _total) when target < dice do
0
@robertsosinski
robertsosinski / dice.rb
Created January 4, 2017 22:36
Dice Rolling
$odds = 0
def sumProbability(dice, target)
if dice == 1
"1 / 6"
else
prob = 6 ** dice
total = 6 * dice
if target < dice
@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.