Skip to content

Instantly share code, notes, and snippets.

View SKoschnicke's full-sized avatar

Sven Koschnicke SKoschnicke

View GitHub Profile
<?php
class Test {
private $number = 0;
private $sub;
public function __construct($n) {
$this->number = $n;
$this->sub = new SubTest($n, $this);
echo "construct ".$this->number."\n";
@SKoschnicke
SKoschnicke / ExampleForSO.hs
Created June 17, 2013 09:56
Source for StackOverflow Question: Change element of list if it holds against some condition or add a new one if not, using Data.Lens (http://stackoverflow.com/questions/17087663)
{-# LANGUAGE TemplateHaskell, Rank2Types #-}
module ExampleForSO where
import Control.Lens
import Control.Applicative ((<$>), pure)
import Data.List (any)
data SomeRec = SomeRec { _name :: String, _val :: Int }
deriving (Show)
$(makeLenses ''SomeRec)
@SKoschnicke
SKoschnicke / error.hs
Created November 6, 2012 12:41
Elegant Haskell error handling
import Control.Error
-- A made-up type for this example.
-- This is a bit simplified because mostly there are not only these encapsuled
-- types but dependent values which can only be retrieved sequentially (e.g.
-- reading an id from stdin, then retrieving the record for this id from a
-- database).
type MyType = (Maybe (Maybe Int))
-- The goal: Return the int when it is less than 10, on other cases (greater or
@SKoschnicke
SKoschnicke / gist:3917956
Created October 19, 2012 12:17
JQuery append only accepts real JS arrays, not JQuery-objects representing arrays (as map returns). Solution: Convert to JS array with makeArray.
$('<tr></tr>').append(
$.makeArray($(data).map(function(index, element) {
return $('<td></td>').html(element.instrument_name)
}))
).appendTo(custom_factor_table)
$('<tr></tr>').append(
$.makeArray($(data).map(function(index, element) {
return $('<td></td>').html('bla')
}))
).appendTo(custom_factor_table)
@SKoschnicke
SKoschnicke / bar.rb
Created August 24, 2012 07:48
Rails habtm extend
class Bar < ActiveRecord::Base
attr_accessible :rec_type
end
import System.IO
import Numeric(showIntAtBase)
import Char(ord, intToDigit)
main :: IO ()
main = do
output stdin
printFile :: String -> IO ()
printFile filename =
@SKoschnicke
SKoschnicke / consistency_problem.rb
Created January 26, 2010 12:03
Concurrency problems with Rails' ActiveRecord
class A < ActiveRecord::Base
# has attribute "value"
end
class B < ActiveRecord::Base
has_many :as
@SKoschnicke
SKoschnicke / xmonad-problem.org
Last active August 29, 2015 14:17
XMonad two instead four monitors
ghc -e "Graphics.X11.openDisplay [] >>= Graphics.X11.Xinerama.getScreenInfo"

results in

[Rectangle {rect_x = 4080, rect_y = 584, rect_width = 1920, rect_height = 2160}, -- D, DP-4.9
 Rectangle {rect_x = 2160, rect_y = 584, rect_width = 1920, rect_height = 2160}, -- C, DP-4.8
 Rectangle {rect_x = 0, rect_y = 1920, rect_width = 2160, rect_height = 1920}, -- B, DP-2.8
@SKoschnicke
SKoschnicke / keybase.md
Created September 18, 2014 10:35
keybase.md

Keybase proof

I hereby claim:

  • I am SKoschnicke on github.
  • I am skoschnicke (https://keybase.io/skoschnicke) on keybase.
  • I have a public key whose fingerprint is 00F0 5868 1412 6596 C9FF ACFB A408 2AE0 90DE 5CE9

To claim this, I am signing this object:

import Reactive.Banana
import Control.Concurrent
main = do
-- Create handles for pushing values into events
(addHandler1, push1) <- newAddHandler
(addHandler2, push2) <- newAddHandler
-- Create event network
network <- compile $ do
-- Actual events from AddHandlers