Skip to content

Instantly share code, notes, and snippets.

View richashworth's full-sized avatar

Richard Ashworth richashworth

View GitHub Profile
@noelwelsh
noelwelsh / Website.scala
Created May 12, 2017 16:19
Simple website login implemented using the free monad
object Website {
import cats.free.Free
import cats.Comonad
import scala.io._
final case class User(username: String)
sealed trait Page
final case object Welcome extends Page
final case object TryAgain extends Page

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
package dojo
/**
* Created with IntelliJ IDEA.
* User: Jim Collins
* Date: 17/09/2015
*/
trait Lcd {
val contents: List[String]
override def toString = contents mkString "\n"
@chemacortes
chemacortes / dedupe.scala
Created February 26, 2014 13:10
Remove duplicates from list in scala (but use better `list.distinct`)
object ListUtil {
def dedupe[T](elements:List[T]):List[T] = elements match {
case Nil => elements
case head::tail => head :: dedupe(tail filterNot (_==head))
}
}
import ListUtil._
@EinfachToll
EinfachToll / vwtags.py
Created February 18, 2014 14:04
Vimwiki Tagbar integration
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Put this file anywhere and add the following to your .vimrc.
# The value of ctagsargs must be one of 'default', 'markdown' or 'media'.
#
# let g:tagbar_type_vimwiki = {
# \ 'ctagstype':'vimwiki'
# \ , 'kinds':['h:header']
# \ , 'sro':'&&&'
@richashworth
richashworth / gist:8138799
Created December 26, 2013 21:17
Fix for Jetpack RSS Widget
if ( 'text-image' == $format )
$link_item .= '<p>&nbsp;<a href="' . get_bloginfo($rss_type) . '" title="' . esc_attr( $subscribe_to ) . '"><br/>' . esc_html__('RSS - ' . $type_text, 'jetpack'). '</a></p>';
@loicdescotte
loicdescotte / Forcomptran.md
Last active May 27, 2023 06:27
Scala for comprehension translation helper

Scala for comprehension translation helper

"For comprehension" is a another syntaxe to use map, flatMap and withFilter (or filter) methods.

yield keyword is used to aggregate values in the resulting structure.

This composition can be used on any type implementing this methods, like List, Option, Future...

@derekwyatt
derekwyatt / ACoupleOfUseExamples.scala
Created July 18, 2012 20:51
Scalatest Fixtures and Akka - parallel fixture isolation - sequential fixture isolation - and no fixture
// Examples showing how to use the specification helpers
//
import akka.actor.ActorSystem
import akka.testkit.{TestKit, ImplicitSender}
import org.scalatest.{WordSpec, BeforeAndAfterAll}
import org.scalatest.matchers.MustMatchers
// Sequentially runs the tests, isolating the Fixture in each test. The Fixture carries the TestKit
// so each test gets its own ActorSystem
class MyAkkaTestSpec extends SequentialAkkaSpecWithIsolatedFixture {
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active May 10, 2024 16:49
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@richashworth
richashworth / ResultsWriterTest.java
Last active March 1, 2019 18:54
Unit Test used in PowerMock Example
package com.richashworth.powermockexample;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;