Skip to content

Instantly share code, notes, and snippets.

View AlanVerbner's full-sized avatar

Alan Verbner AlanVerbner

View GitHub Profile
# Just put this in your cron (Runs every 1 minute).
# * * * * * /home/YOURUSERNAME/bin/suspend-on-low-battery
source /nix/var/nix/profiles/system/etc/profile
UPOWER=$(nix-build -A upower '<nixpkgs>')/bin/upower
NOTIFY_SEND=$(nix-build -A libnotify '<nixpkgs>')/bin/notify-send
DISPLAY=:0.0
battery_device=`$UPOWER -e | grep -i battery | head -n 1`
@oinopion
oinopion / read-access.sql
Created October 5, 2016 13:00
How to create read only user in PostgreSQL
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;

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
@PurpleBooth
PurpleBooth / README-Template.md
Last active April 18, 2024 00:56
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@fancellu
fancellu / ShapelessCoproduct.scala
Last active February 20, 2023 10:02
Examples with Shapeless 2.0, easier to understand from examples. Taken from docs, more examples/comments added etc
// Coproduct is extension of Either concept, to N multually exlusive choices
type ISB = Int :+: String :+: Boolean :+: CNil
val isb = Coproduct[ISB]("foo") //> isb : qaaz.ISB = foo
isb.select[Int] //> res0: Option[Int] = None
isb.select[String] //> res1: Option[String] = Some(foo)
@staltz
staltz / introrx.md
Last active April 19, 2024 18:49
The introduction to Reactive Programming you've been missing
@mingfang
mingfang / JSXTransformer.java
Last active October 10, 2020 05:45
Java tool to transform React JSX into Javascript
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.NativeObject;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.commonjs.module.Require;
import org.mozilla.javascript.commonjs.module.RequireBuilder;
import org.mozilla.javascript.commonjs.module.provider.SoftCachingModuleScriptProvider;
import org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider;
import java.io.File;
@ndarville
ndarville / business-models.md
Last active January 13, 2024 17:27
Business models based on the compiled list at http://news.ycombinator.com/item?id=4924647. I find the link very hard to browse, so I made a simple version in Markdown instead.

Business Models

Advertising

Models Examples
Display ads Yahoo!
Search ads Google
@kendellfab
kendellfab / versionswitch.sh
Created July 14, 2012 15:35
Bash script for changing version code and version name in an android manifest.
MANIFEST_FILE='AndroidManifest.xml'
VERSIONCODE=`grep versionCode $MANIFEST_FILE | sed 's/.*versionCode="//;s/".*//'`
VERSIONNAME=`grep versionName $MANIFEST_FILE | sed 's/.*versionName="//;s/\.[0-9]*".*//'`
NEWCODE=$BUILD_NUMBER
NEWNAME=$VERSIONNAME.$BUILD_NUMBER
echo "Updating Android build information. New version code: $NEWCODE - New version name: $NEWNAME";
sed -i 's/versionCode *= *"'$VERSIONCODE'"/versionCode="'$NEWCODE'"/; s/versionName *= *"[^"]*"/versionName="'$NEWNAME'"/' $MANIFEST_FILE
@retronym
retronym / type-bounds.scala
Created December 16, 2009 11:17
Tour of Scala Type Bounds
class A
class A2 extends A
class B
trait M[X]
//
// Upper Type Bound
//
def upperTypeBound[AA <: A](x: AA): A = x