Skip to content

Instantly share code, notes, and snippets.

View metasim's full-sized avatar
🇺🇦

Simeon H.K. Fitch metasim

🇺🇦
View GitHub Profile
@zacharycarter
zacharycarter / wclwn.md
Last active March 12, 2024 12:45
Binding to C Libraries with Nim
@jsuereth
jsuereth / sbt-build-structure.md
Created June 15, 2015 14:56
Sbt build structure

Here's a short little guide to sbt's build structure.

First off, the key you need to investigate how sbt is building things. Here's a snippet from a build.sbt:

import sbt.Keys._
val bs: sbt.BuildStructure = buildStructure.value

This will give you all the gory details of our build (or builds, as is the case).

@non
non / answer.md
Last active January 9, 2024 22:06
answer @nuttycom

What is the appeal of dynamically-typed languages?

Kris Nuttycombe asks:

I genuinely wish I understood the appeal of unityped languages better. Can someone who really knows both well-typed and unityped explain?

I think the terms well-typed and unityped are a bit of question-begging here (you might as well say good-typed versus bad-typed), so instead I will say statically-typed and dynamically-typed.

I'm going to approach this article using Scala to stand-in for static typing and Python for dynamic typing. I feel like I am credibly proficient both languages: I don't currently write a lot of Python, but I still have affection for the language, and have probably written hundreds of thousands of lines of Python code over the years.

@mbedward
mbedward / gist:6e3dbb232bafec0792ba
Last active September 26, 2021 14:08
Scala macro to convert between a case class instance and a Map of constructor parameters. Developed by Jonathan Chow (see http://blog.echo.sh/post/65955606729/exploring-scala-macros-map-to-case-class-conversion for description and usage). This version simply updates Jonathan's code to Scala 2.11.2
import scala.language.experimental.macros
import scala.reflect.macros.blackbox.Context
trait Mappable[T] {
def toMap(t: T): Map[String, Any]
def fromMap(map: Map[String, Any]): T
}
object Mappable {
@plesner
plesner / polyenum.hs
Last active February 9, 2017 02:55
Polynomial range function in haskell
-- Given a list of values, returns a list of the differences between
-- neighbouring pairs of values.
nextLevelDiffs (a:b:rest) = (b - a):(nextLevelDiffs (b:rest))
nextLevelDiffs _ = []
-- Given a list of values, returns a list of the differences such that the
-- first element is the 0-level differences, the second the 1-level and so
-- on.
nLevelDiffs [] = []
nLevelDiffs elms = elms:(nLevelDiffs (nextLevelDiffs elms))

Desugar Scala Expressions

Use the compiler

scala -Xprint:typer -e "class A(val i: Int)" prints the desugarred expression after the typer phase. Use scala -Xshow-phases to get a list of all phases.

Or use a macro in the REPL

Paste this into a REPL session or in a file loaded with the :load command:

@tonymorris
tonymorris / type-class.scala
Last active December 23, 2015 04:18
Scala type-class hierarchy
import annotation._
case class Pronunciation(pronounce: String) extends StaticAnnotation
case class Law(name: String, denotation: String) extends StaticAnnotation
trait ~>[F[_], G[_]] {
def apply[A]: F[A] => G[A]
}
case class Id[A](x: A)
@hanny24
hanny24 / comp.rs
Created June 10, 2013 15:31
Simple Scala-like for comprehension for rust
// Simple Scala-like for comprehension for rust
macro_rules! comp(
// base case, using "map"
(val $id:ident <- $expr:expr $(,if $cond:expr)* $(,let $assign_id:pat = $assign_val:expr)* ,yield $comp:expr) =>
(
($expr)$(.filtered(|&$id| $cond))*.map(|&$id| {
$(let $assign_id = $assign_val;)* $comp
}
)
@fozziethebeat
fozziethebeat / SchiselClassify.scala
Created February 8, 2012 00:55
SchiselClassify, A wrapper around Mallet's classifier instance for arbitrary feature spaces within Scala
/*
* Copyright (c) 2012, Lawrence Livermore National Security, LLC. Produced at
* the Lawrence Livermore National Laboratory. Written by Keith Stevens,
* kstevens@cs.ucla.edu OCEC-10-073 All rights reserved.
*
* This file is part of the S-Space package and is covered under the terms and
* conditions therein.
*
* The S-Space package is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as published
@softprops
softprops / key_opts.md
Created June 24, 2011 06:11
sbt function operator cheatsheet

key independent functions

:=   binds single value
+=   appends single value
++=  appends seq of values

key dependent functions

<<=  binds single value

<+= appends single value