Skip to content

Instantly share code, notes, and snippets.

View Softsapiens's full-sized avatar

Daniel Pous Montardit Softsapiens

View GitHub Profile
@djspiewak
djspiewak / streams-tutorial.md
Created March 22, 2015 19:55
Introduction to scalaz-stream

Introduction to scalaz-stream

Every application ever written can be viewed as some sort of transformation on data. Data can come from different sources, such as a network or a file or user input or the Large Hadron Collider. It can come from many sources all at once to be merged and aggregated in interesting ways, and it can be produced into many different output sinks, such as a network or files or graphical user interfaces. You might produce your output all at once, as a big data dump at the end of the world (right before your program shuts down), or you might produce it more incrementally. Every application fits into this model.

The scalaz-stream project is an attempt to make it easy to construct, test and scale programs that fit within this model (which is to say, everything). It does this by providing an abstraction around a "stream" of data, which is really just this notion of some number of data being sequentially pulled out of some unspecified data source. On top of this abstraction, sca

@milessabin
milessabin / gist:65fa0d4ef373781d3ab4
Last active July 23, 2017 11:17
Empty refinements prevent unwanted widening when assigning singleton-typed values to a val.
// Used in shapeless here: https://github.com/milessabin/shapeless/blob/master/core/src/main/scala/shapeless/syntax/singletons.scala#L42
scala> def narrow[T <: AnyRef](t: T): t.type = t
narrow: [T <: AnyRef](t: T)t.type
scala> val s1 = narrow("foo") // Widened
s1: String = foo
scala> def narrow[T <: AnyRef](t: T): t.type {} = t // Note empty refinement
narrow: [T <: AnyRef](t: T)t.type

doobie experiment - postgres NOTIFY as scalaz-stream

One of the cool things PostgreSQL gives you is a simple notification system that you can use to let clients know that something interesting has happened. For instance you can set up rules that broadcast notifications when a table is updated, and client applications can update displays in response. The JDBC driver provides access to this API so I thought I would see what it would look like in doobie.

The program below constructs a Process[ConnectionIO, PGNotification] that registers for events, polls for them periodically (this is the best we can do with current driver support), and unregisters when the stream terminates for any reason. We use a Transactor to replace ConnectionIO with Task which gives us something we can actually run.

package doobie.example

import doobie.imports._
@SimonRichardson
SimonRichardson / AddressBook.purs
Last active January 28, 2016 13:24
Validation.purs
module Data.AddressBook where
import Data.Maybe
newtype Address = Address
{ street :: String
, city :: String
, state :: String
}
@nickbutcher
nickbutcher / 1 search_bar.xml
Last active March 12, 2026 14:50
Demonstrating morphing a search icon into a search field. To do this we use an AnimatedVectorDrawable (https://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html) made up of two paths. The first is the search icon (as a single line) the second is the horizontal bar. We then animate the 'trimPathStart' property …
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
@johnynek
johnynek / AliceInAggregatorLand.scala
Last active January 24, 2024 19:38
A REPL Example of using Aggregators in scala
/**
* To get started:
* git clone https://github.com/twitter/algebird
* cd algebird
* ./sbt algebird-core/console
*/
/**
* Let's get some data. Here is Alice in Wonderland, line by line
*/
@johnynek
johnynek / dependent_type_question.scala
Last active August 29, 2015 14:11
type inference with cases. Why does this fail in scala 2.10.4? Is my logic wrong, or is the compiler not smart enough?
sealed trait Key {
type Inner
}
trait IntKey extends Key {
type Inner = Int
}
trait StringKey extends Key {
type Inner = String
}
@paf31
paf31 / 24days.md
Last active August 8, 2023 05:53
24 Days of PureScript

This blog post series has moved here.

You might also be interested in the 2016 version.

@lsd
lsd / IdeaVim OS X Key Repeat.markdown
Last active May 21, 2026 17:26
Enable key-repeat for ALL applications or just for IdeaVim/specific JetBrains apps

Upgrading to Lion or Yosemite and WebStorm 9, I noticed key repeat was
turned off for the IdeaVim plugin h j k l keys.

System-wide key repeat

defaults write -g ApplePressAndHoldEnabled -bool false in a terminal will enable
key repeat for every app. This can alternatively be found in the accessibility settings in OS X' preferences.

App specific key repeat

@bvenners
bvenners / gist:b129cccf6d6486316030
Created November 5, 2014 08:12
Example showing Scalactic's Validation used to accumulate errors with the "when" combinator
scala> import org.scalactic._
import org.scalactic._
// A Validation is either a Pass or a Fail. A Validation is like an
// Option with the reverse attitude: Pass is like None, it contains no
// value and just means the value being validated is OK as is. Fail is
// like Some, it holds an error value describing the validation failure.
scala> def isPositive(i: Int): Validation[ErrorMessage] =
| if (i > 0) Pass else Fail(s"$i was not positive")
isPositive: (i: Int)org.scalactic.Validation[org.scalactic.ErrorMessage]