Skip to content

Instantly share code, notes, and snippets.

using System;
using Gtk;
using WebKit;
namespace monobrowser {
class coolbrowser {
public static void Main () {
Application.Init ();
Window window = new Window ("a browser in 13 lines...");
@caiorss
caiorss / 01_MainWindow.cs
Created March 10, 2017 17:31
Monoのサンプルコード
using System;
using Gtk;
public partial class MainWindow: Gtk.Window
{
public MainWindow () : base (Gtk.WindowType.Toplevel)
{
Window myWin = new Window ("My first GTK# Application!");
myWin.Resize (200, 200);
//
// AndroidDesignerView.cs
//
// Author:
// Lluis Sanchez <[email protected]>
//
// Copyright (c) 2011 Xamarin Inc
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@caiorss
caiorss / Main.cs
Created March 10, 2017 17:28 — forked from carlosmn/Main.cs
Gtk#-3 with GtkBuilder
using System;
using Gtk;
namespace builder
{
class MainWin
{
[Gtk.Builder.Object("window1")] Window window1;
public void OnToggled(object sender, EventArgs args)
{
@caiorss
caiorss / Reader.scala
Created March 10, 2017 17:26 — forked from kafecho/Reader.scala
Example of using the Reader Monad.
package org.kafecho.learning.monad
import java.util.UUID
/** My attempt at implementing the Reader Monad concept.
* The Reader Monad encapsulates a computation which:
* - requires a dependency of type D
* - produces values of type A.
*/
case class Reader[D, A](computation: D => A) {
@caiorss
caiorss / gist:6a0f3fcbbea329931dca58217e3ece97
Created March 10, 2017 16:54 — forked from chrislewis/gist:3416494
reader monad for java.util.Properties example
/* Start by creating a reader for some fake yet conceivable type for executing SQL queries. */
val dbReader: Reader[Properties, JdbcExecutor] =
for {
driver <- read[String]("db.driver")
uri <- read[String]("db.uri")
user <- read[String]("db.username")
password <- read[String]("db.password")
name <- read[String]("db.pool.name")
minCons <- read[Int]("db.pool.minConnections")
@caiorss
caiorss / reader-resources.scala
Created March 10, 2017 16:51 — forked from balajisivaraman/reader-resources.scala
Reader Monad Resource Management
val getJDBCConnection: Reader[JDBCConf, Connection] = ???
val getStatement: Reader[Connection, PreparedStatement] = ???
val executeQuery: Reader[PreparedStatement, ResultSet] = ???
val queryExecutor: Reader[JDBCConf, ResultSet] = getJDBCConnection.andThen(getStatement).andThen(executeQuery)
Monad | effect | sequences the effect as | M[A] | bind: M[A] => (f: A => M[B]) => M[B]
Identity | nothing | continue | Id[A] | f(a)
Option | zero or one value (anonymous exception) | halt if None | Option[A] | if Some(a) f(a)
Either | exception with error type or one value | halt if Left | Either[L, A] | if Right(a) f(a)
List | any # of values (non-determinism) | halt if empty | List[A] | join(each f(a))
Reader | an environment; dependency-injection | function composition | R => A | (r: R) => f(a(r))
Writer | logging | append log value W | Writer[W, A](log: W, value: A) | k = f(a.value); Writer(a.log |+| k.log, k.value)
State | state | new state from old | State[S, A](s: S => (S, A)) |
Responder | continuation-passing
@caiorss
caiorss / Example.scala
Last active March 10, 2017 16:47 — forked from echeipesh/Reader.scala
Reader Monad
/// REPL Testing
//
// -----------------------------------------
$ scala
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_20).
Type in expressions for evaluation. Or try :help.
scala> case class Reader[C, A](g: C => A) {
| def apply(c: C) = g(c)
@caiorss
caiorss / Reader.scala
Created March 10, 2017 15:42 — forked from blouerat/Reader.scala
Reader Monad
/*
Based on the first part of the talk "Dead-Simple Dependency Injection in Scala" by @runarorama at NEScala 2012
http://marakana.com/s/dependency_injection_in_scala,1108/index.html
*/
class Connection {
def prepareStatement(query: String) = new Statement()
}
class Statement {