Skip to content

Instantly share code, notes, and snippets.

View mnn's full-sized avatar

monnef mnn

View GitHub Profile
@m242
m242 / gist:1205631
Created September 9, 2011 06:43
Scala Option in JavaScript
var MyOption, Option;
Array.prototype.filter = function(f) {
var x, _i, _len, _results;
_results = [];
for (_i = 0, _len = this.length; _i < _len; _i++) {
x = this[_i];
if (f(x)) {
_results.push(x);
}
@lossyrob
lossyrob / write-one-line-text.scala
Last active August 14, 2019 07:54
Read \ Write a text file in one line Scala
def write(path: String, txt: String): Unit = {
import java.nio.file.{Paths, Files}
import java.nio.charset.StandardCharsets
Files.write(Paths.get(path), txt.getBytes(StandardCharsets.UTF_8))
}
def read(path: String): String =
scala.io.Source.fromFile(path, "UTF-8").getLines.mkString
@Bunyod
Bunyod / Entities.scala
Created October 27, 2016 07:27
Slick one to many and grouping
object Entities {
case class Review(txt: String, userId: Long, id: Long)
case class User(name: String, id: Long)
case class ReviewEvent(event: String, reviewId: Long)
case class FullReview(r: Review, user: User, evts: Seq[ReviewEvent])
}
@ikhoon
ikhoon / must-watch-talks.md
Last active April 14, 2020 10:46
Must watch talks - reddit /r/scala
#!/usr/bin/python3
from bluepy import btle
import sys
class DiscoLH(btle.DefaultDelegate):
def __init__(self):
self.devices = []
btle.DefaultDelegate.__init__(self)
@Programie
Programie / pa-app-sink-switcher.py
Last active December 24, 2022 08:57
Toggle PulseAudio output sink for the active application
#! /usr/bin/env python3
# This script toggles the PulseAudio output sink of the currently active application (guessed by the currently active X window) between the given output sink and the default output sink.
# The output sink is passed as first argument to the script.
#
# Requirements:
#
# xdotool (on Ubuntu install via "sudo apt install xdotool")
# pulsectl ("sudo pip3 install pulsectl")
@DaveKin
DaveKin / _propmap.scss
Last active February 22, 2023 13:05
Utility SASS mixin to convert a map of property names and values to CSS
/**
* Converts a SASS map of css property names and values into CSS output.
* Properties named `description` will have their value inserted as comments.
*
* Nested maps will be processed recursively.
*
* @param {map} $map the map of properties to output
*/
@mixin map-to-props($map){
@if type-of($map) == map {
@evincarofautumn
evincarofautumn / InlineDoBind.md
Last active April 20, 2023 21:16
Thoughts on an InlineDoBind extension

Thoughts on an InlineDoBind extension

An expression beginning with a left arrow (<-) inside a do block statement is desugared to a monadic binding. This is syntactically a superset of existing Haskell, including extensions. It admits a clean notation that subsumes existing patterns and comes with few downsides.

Examples

do
  f (<- x) (<- y)
-- ===
@ryleu
ryleu / linuxoverwatch.md
Last active May 31, 2023 07:44
OW 2 on Linux

This guide is completely irrelevant! You no longer need to follow anything here—doing so may actually harm performance rather than helping it. Please tell whoever linked you here that they need to maintain their own guide, if they want to help people set up newer versions of DXVK / etc.

@ramn
ramn / Deserialization.scala
Last active October 18, 2023 17:42
Object serialization example in Scala
import java.io._
@SerialVersionUID(15L)
class Animal(name: String, age: Int) extends Serializable {
override def toString = s"Animal($name, $age)"
}
case class Person(name: String)
// or fork := true in sbt