Skip to content

Instantly share code, notes, and snippets.

View maciejsmolinski's full-sized avatar

Maciej Smolinski maciejsmolinski

View GitHub Profile
data State:
| notAsked
| loading
| failure(error)
| success(result)
end
fun result(state):
doc: "Returns custom message for given state"
@maciejsmolinski
maciejsmolinski / exception.hs
Created November 12, 2017 19:25
Haskell - Custom Exception
{-# LANGUAGE OverloadedStrings #-}
import Prelude
import Control.Exception
data Err = Err String
instance Show Err where
show (Err value) = show value
@maciejsmolinski
maciejsmolinski / counter.re
Created September 13, 2017 08:27
A simple counter in ReasonML
type stateType = { counter: int };
let initialState: stateType = { counter: 0 };
type actionType =
| Increment
| Decrement
| Reset;
let update action state =>
@maciejsmolinski
maciejsmolinski / SassMeister-input.scss
Created January 18, 2016 09:35
Generated by SassMeister.com.
// ----
// libsass (v3.3.2)
// ----
.flex {
display: flex;
&--space-around {
justify-content: space-around;
}
@maciejsmolinski
maciejsmolinski / wallet-aop.es6
Created February 20, 2015 13:45
AOP ES6 (Wallet)
class AOP {
static extend(target) {
Object.assign(target, AOP.prototype);
}
}
AOP.prototype.before = function (property, fn) {
let oldProperty = this[property];
this[property] = function () {
fn.apply(this, arguments);
@maciejsmolinski
maciejsmolinski / wallet.es6
Created February 20, 2015 13:29
ES6 AOP Wallet
class AOP {
static extend(target) {
Object.assign(target, AOP.prototype);
}
}
AOP.prototype.before = function (property, fn) {
let oldProperty = this[property];
this[property] = function () {
fn.apply(this, arguments);
@maciejsmolinski
maciejsmolinski / wallet.js
Created February 20, 2015 09:06
Wallet.js (PoC)
app.service('Wallet', function () {
function Wallet () {
this.total = 0;
}
Wallet.prototype.add = function (amount) {
this.total += Number(amount) || 0;
return this.total;
};
@maciejsmolinski
maciejsmolinski / repository.es6
Created February 19, 2015 22:47
ES6 Repo + DI
class CoreRepository {
static inject () {
return [];
}
static instance () {
var deps = this.inject();
return new this(...deps);
}
}
@maciejsmolinski
maciejsmolinski / max2.sjs
Last active August 29, 2015 13:56
Math.max taking arrays implemented in sweet.js
/* sweet.js (sjs) markup, can be compiled on http://sweetjs.org/browser/editor.html */
let Math.max = macro {
rule { ([$x ...]) } => { Math.max ($x ...) }
rule { ($x ...) } => { Math.max ($x ...) }
}
// 1. Regular
Math.max(1,2) // => Math.max(1,2)
Math.max(3,4,5) // => Math.max(3,4,5)
describe User do
include ClassHelpers
context "new" do
it "should create user with role_id = 2 (registered) by default" do
new_valid_user.role_id.should == 2
new_valid_user.registered?.should be_true
end