Skip to content

Instantly share code, notes, and snippets.

View malzzz's full-sized avatar

Mallory M. malzzz

  • Bivalent Capital
  • /dev/null
View GitHub Profile
@non
non / beala.scala
Created May 9, 2016 00:07
Demo using Cats/Dogs to implement lazy memoization, similar to this Haskell gist: https://gist.github.com/beala/d871ae8397167e7035f218a25ddf87dd
package beala
import dogs._
object Beala {
// ironically dogs doesn't support unsafe operations by default,
// so we have to build them ourselves (since we know our stream
// is infinite and will always have elements).
def head[A](as: Streaming[A]): A =
@beala
beala / fibsMemo.hs
Created May 8, 2016 23:25
Elegant memoization in Haskell with laziness.
import Control.Monad.State.Strict
import qualified Data.Map.Strict as Map
-- This is the standard fibonacci implementation with exponential complexity.
naiveFibs :: Int -> Integer
naiveFibs 0 = 0
naiveFibs 1 = 1
naiveFibs n = naiveFibs (n-2) + naiveFibs (n-1)
-- For reference, calculating the 35th fibonacci takes 9.49 sec.
@Frozenfire92
Frozenfire92 / gist:3627e38dc47ca581d6d024c14c1cf4a9
Last active December 15, 2024 08:15
Install Scala and SBT using apt-get on Ubuntu 16.04 or any Debian derivative using apt-get
## Java
sudo apt-get update
sudo apt-get install default-jdk
## Scala
sudo apt-get remove scala-library scala
sudo wget http://scala-lang.org/files/archive/scala-2.12.1.deb
sudo dpkg -i scala-2.12.1.deb
sudo apt-get update
sudo apt-get install scala
@etorreborre
etorreborre / effForReal.scala
Last active September 7, 2016 03:22
Using Eff on a "real" use case
/**
* We need to create bidirectional maps for items having both a name an an id
* When we collect items, we need to check that there are no duplicated names or ids for a given item
*/
// first let's define bi-directional maps
case class BiMap[K, V](keys: Map[K, V], values: Map[V, K]) {
def add(entry: BiMapEntry[K, V]): BiMap[K, V] =
BiMap(keys + (entry.key -> entry.value), values + (entry.value -> entry.key))
@spietz-handy
spietz-handy / AddressCache.hs
Created February 29, 2016 16:12
Lock-free cache implemented using Haskel STM
module AddressCache where
import qualified Data.Bimap as B
import Data.DateTime
import Control.Concurrent.STM
import Control.Concurrent
import Control.Monad
type InetAddress = Integer

10 Scala One Liners to Impress Your Friends

Here are 10 one-liners which show the power of scala programming, impress your friends and woo women; ok, maybe not. However, these one liners are a good set of examples using functional programming and scala syntax you may not be familiar with. I feel there is no better way to learn than to see real examples.

Updated: June 17, 2011 - I'm amazed at the popularity of this post, glad everyone enjoyed it and to see it duplicated across so many languages. I've included some of the suggestions to shorten up some of my scala examples. Some I intentionally left longer as a way for explaining / understanding what the functions were doing, not necessarily to produce the shortest possible code; so I'll include both.

1. Multiple Each Item in a List by 2

The map function takes each element in the list and applies it to the corresponding function. In this example, we take each element and multiply it by 2. This will return a list of equivalent size, compare to o

@lukas-h
lukas-h / license-badges.md
Last active July 8, 2026 15:18
Markdown License Badges for your Project

Markdown License badges

Collection of License badges for your Project's README file.
This list includes the most common open source and open data licenses.
Easily copy and paste the code under the badges into your Markdown files.

Notes

  • The badges do not fully replace the license informations for your projects, they are only emblems for the README, that the user can see the License at first glance.

Translations: (No guarantee that the translations are up-to-date)

@xndc
xndc / tunejack.sh
Last active January 15, 2026 19:27
Instant radio streaming script using the TuneIn API
#!/bin/bash
# tunejack.sh uses the TuneIn public API (at opml.radiotime.com) to search for
# a radio station, print out its details and try to play it somehow.
if [ "$#" -eq 0 ]; then
echo "$0: search for a radio station using the TuneIn API"
echo "Usage: $0 PATTERN"
exit 1
fi
@pchiusano
pchiusano / diamonds.scala
Created December 8, 2015 20:06
Design of splitting combinators in FS2
package fs2
import util.Monad
import Step._
import java.util.concurrent.atomic.AtomicLong
object diamond {
/**
* Pass elements of `s` through both `f` and `g`, then combine the two resulting streams.
@noelwelsh
noelwelsh / loop.scala
Created October 15, 2015 16:18
Example of monadic loop using the State monad in Cats
import cats.{Id,Monad}
import cats.state.State
import cats.std.function._
import scala.language.higherKinds._
// Call Example.example.run to see the example running
object Example {
type MyState[A] = State[Int, A]