Skip to content

Instantly share code, notes, and snippets.

View malzzz's full-sized avatar

Mallory M. malzzz

  • Asymmetric Finance
  • /dev/null
View GitHub Profile
@Frozenfire92
Frozenfire92 / gist:3627e38dc47ca581d6d024c14c1cf4a9
Last active October 20, 2021 20:58
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 May 11, 2024 05:17
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 March 10, 2024 16:42
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]
@djspiewak
djspiewak / 0introduction.md
Last active November 28, 2023 15:03
Scala Collections Proposal

Collections Redesign Proposal

I'm going to start off by motivating what I'm doing here. And I want to be clear that I'm not "dissing" the existing collections implementation or anything as unproductively negative as that. It was a really good experiment, it was a huge step forward given what we knew back in 2.8, but now it's time to learn from that experiment and do better. This proposal uses what I believe are the lessons we can learn about what worked, what didn't work, and what is and isn't important about collections in Scala.

This is going to start out sounding really negative and pervasively dismissive, but bear with me! There's a point to all my ranting. I want to be really clear about my motivations for the proposal being the way that it is.

Problems

Generic Interfaces

@rzeigler
rzeigler / TerminalIO.hs
Last active September 12, 2016 17:40
Translation of https://github.com/tpolecat/examples/blob/master/src/main/scala/eg/FreeMonad.scala FreeMonad example to Haskell as well as an example program.
import Control.Monad.Free
import Control.Monad.State.Lazy
data TerminalOp a = ReadLine (String -> a) | WriteLine String a
instance Functor TerminalOp where
fmap f (ReadLine g) = ReadLine (f . g)
fmap f (WriteLine s a) = WriteLine s (f a)
type TerminalIO a = Free TerminalOp a