Skip to content

Instantly share code, notes, and snippets.

View bbarker's full-sized avatar

Brandon Elam Barker bbarker

View GitHub Profile

Class import magic

Demonstrate how to get things to magically happen when you import instances of a class.

@leroycep
leroycep / shell.nix
Created April 14, 2019 16:17
nix-shell environment for running veloren
let
moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
nixpkgs = import <nixpkgs> { overlays = [ moz_overlay ]; };
in
with nixpkgs;
stdenv.mkDerivation {
name = "veloren-env";
buildInputs = [
(nixpkgs.rustChannelOf { date = "2019-04-11"; channel = "nightly"; }).rust
git
package a8.scalajs.ui
import cats.implicits._
import mhtml._
import mhtml.implicits.cats._
import a8.common.Labeler
import a8.manna.model.ElementId
import a8.scalajs.Events
import org.scalajs.dom
import org.scalajs.dom.KeyboardEvent
@johnynek
johnynek / scala path dependent serializers.scala
Last active July 17, 2018 21:16
Scala's path dependent types can be used to prove that a serialized value can be deserialized without having to resort to Try/Either/Option. This puts the serialized value into the type, so we can be sure we won't fail. This is very useful for distributed compute settings such as scalding or spark.
import scala.util.Try
object PathSerializer {
trait SerDe[A] {
// By using a path dependent type, we can be sure can deserialize without wrapping in Try
type Serialized
def ser(a: A): Serialized
def deser(s: Serialized): A
// If we convert to a generic type, in this case String, we forget if we can really deserialize
@zeenix
zeenix / pre-commit
Created December 13, 2017 14:59
git hook to ensure commit doesn't break rustfmt
#!/bin/sh
# Put in your Rust repository's .git/hooks/pre-commit to ensure you never
# breaks rustfmt.
#
# WARNING: rustfmt is a fast moving target so ensure you have the version that
# all contributors have.
for FILE in `git diff --cached --name-only`; do
#if [[ $FILE == *.rs ]] && ! rustup run nightly rustfmt --write-mode diff --skip-children $FILE; then
@mickours
mickours / release.nix
Last active June 19, 2018 20:00
Nix environment for releasing pypi package
# Use this environment to publish this package on pypi:
#
# # Enter the environment
# nix-shell release.nix
#
# # create the package
# python setup.py bdist
#
# # register to pypi (if not registered yet)
# twine register dist/project_name-x.y.z.tar.gz
@mugifly
mugifly / docker-clean.sh
Created August 18, 2016 07:17
Cleanup Script for Docker Images and Containers
#!/bin/sh
echo -e "-- Removing exited containers --\n"
docker ps --all --quiet --filter="status=exited" | xargs --no-run-if-empty docker rm --volumes
echo -e "\n\n-- Removing untagged images --\n"
docker rmi --force $(docker images | awk '/^<none>/ { print $3 }')
echo -e "\n\n-- Removing volume directories --\n"
docker volume rm $(docker volume ls --quiet --filter="dangling=true")
@smarter
smarter / gadt.md
Last active March 6, 2024 23:33
GADTs in Scala

Generalized Algebraic Data Types in Scala

Basic GADTs

Here's an ADT which is not a GADT, in Haskell:

data Expr = IntExpr Int | BoolExpr Bool
@ipbastola
ipbastola / clean-up-boot-partition-ubuntu.md
Last active May 2, 2024 01:27
Safest way to clean up boot partition - Ubuntu 14.04LTS-x64, Ubuntu 16.04LTS-x64

Safest way to clean up boot partition - Ubuntu 14.04LTS-x64, Ubuntu 16.04LTS-x64

Reference

Case I: if /boot is not 100% full and apt is working

1. Check the current kernel version

$ uname -r 
@yoshuawuyts
yoshuawuyts / Q&A.md
Created March 16, 2016 05:58 — forked from novaluke/0-Q&A.md
I want to use Nix for development, but... -- answers to common concerns about Nix

Nix seems perfect for developers - until I try to use it...

Want to use Nix for development but you're not sure how? Concerned about the fluidity of nixpkgs channels or not being able to easily install arbitrary package versions?

When I first heard about Nix it seemed like the perfect tool for a developer. When I tried to actually use it for developing and deploying web apps, though, the pieces just didn't seem to add up.