Skip to content

Instantly share code, notes, and snippets.

@egonSchiele
egonSchiele / canny.cpp
Created December 28, 2010 02:42
Adding automatic thresholding to cvCanny in OpenCV
// new
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
@egonSchiele
egonSchiele / rons.rb
Last active October 30, 2022 06:16
The dining philosophers problem in Ruby, solved using the resource hierarchy solution
require 'thread'
class Ron
def initialize(name, left_fork, right_fork)
@name = name
@left_fork = left_fork
@right_fork = right_fork
while true
think
dine
@egonSchiele
egonSchiele / diners.hs
Last active April 23, 2022 17:29
Dining philosophers solution in Haskell using STM. Taken from http://rosettacode.org/wiki/Dining_philosophers#Haskell with some minor modifications.
import Control.Monad
import Control.Concurrent
import Control.Concurrent.STM
import System.Random
import Text.Printf
-- Forks
type Fork = TMVar Int
newFork :: Int -> IO Fork
@egonSchiele
egonSchiele / reader.hs
Created June 10, 2013 20:51
Reader monad example
import Control.Monad.Reader
hello :: Reader String String
hello = do
name <- ask
return ("hello, " ++ name ++ "!")
bye :: Reader String String
bye = do
name <- ask
@egonSchiele
egonSchiele / Main.hs
Created April 17, 2013 00:03
Read and write from a database using persistent and Scotty
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
@egonSchiele
egonSchiele / regression.m
Last active March 28, 2021 12:46
Linear regression in Octave
% scaled features.
% x = square feet
% y = sale price
x = [1, 2, 4];
y = [2, 2.5, 3];
% function to calculate the predicted value
function result = h(x, t0, t1)
result = t0 + t1 * x;
end
Hi Mayor Carter,
Like many citizens of Saint Paul, I've been glued to the news this week. As protests spread from Minneapolis to Saint Paul, I've been shocked at how cops are ESCALATING this situation instead of DE-ESCALATING it.
We need police reform, and training is not enough.
I want to show you what a cop told me.
"The training involved lecture, personal testimony from people who have had crisis interactions with police, and role-playing scenarios, in which the cops are tested. They generally did not do well. Many didn’t take the training seriously. Most don’t respond well to being challenged. They want to be obeyed. They want total control. People in crisis rarely give them that, and things tend to escalate. The cops are taught how to deescalate situations, using techniques such as mirroring, silence, and modulating the tempo. But, as I said, many of them consider this stuff bullshit. A culture change is necessary, from the top down and from the ground up. A big help would be if cops were legally held
Hi Governor Walz and Lt Governor Flanagan,
Like many citizens of the Twin Cities, I've been glued to the news this week. I want to let you know I'm so thankful that Chauvin got arrested.
Now he needs to be convicted and go to jail.
I've seen again and again that the police get let off with a slap on the wrist. This does not work.
I want to show you what a cop told me.
"The training involved lecture, personal testimony from people who have had crisis interactions with police, and role-playing scenarios, in which the cops are tested. They generally did not do well. Many didn’t take the training seriously. Most don’t respond well to being challenged. They want to be obeyed. They want total control. People in crisis rarely give them that, and things tend to escalate. The cops are taught how to deescalate situations, using techniques such as mirroring, silence, and modulating the tempo. But, as I said, many of them consider this stuff bullshit. A culture change is necessary, from the top down and from the grou
@egonSchiele
egonSchiele / dining_with_waiter.rb
Created May 16, 2013 18:20
Dining philosophers using locks in Ruby. This implements a Waiter who is in charge of forks.
require 'thread'
class Waiter
def initialize
@mutex = Mutex.new
end
def can_eat? philosopher
left = philosopher.left_fork
right = philosopher.right_fork
@egonSchiele
egonSchiele / logistic_regression_grapefruit.m
Created March 10, 2016 03:54
Logistic regression for orange vs grapefruit
% data
x = [1, 2, 3, 4, 5, 6];
y = [0, 0, 0, 1, 1, 1];
% function to calculate the predicted value
function result = h(x, t0, t1)
result = sigmoid(t0 + t1 * x);
end
% sigmoid function