Skip to content

Instantly share code, notes, and snippets.

View AndreasLoukakis's full-sized avatar
💭
Fooing the bar

Andreas Loukakis AndreasLoukakis

💭
Fooing the bar
View GitHub Profile
@AndreasLoukakis
AndreasLoukakis / fp.pipe.js
Created April 23, 2017 22:38
various implementations of pipe in JS
// curried with arrows
const composeMixins = (...mixins) => (
instance = {},
mix = (...fns) => x => fns.reduce((acc, fn) => fn(acc), x)
) => mix(...mixins)(instance);
// vs ES5-style
var composeMixins = function () {
var mixins = [].slice.call(arguments);
return function (instance, mix) {
if (!instance) instance = {};
@AndreasLoukakis
AndreasLoukakis / fp.currying.js
Created April 19, 2017 16:13
Various currying implementations, for reference an comparison
// @Underscore
// Partially apply a function by creating a version that has had some of its
// arguments pre-filled, without changing its dynamic `this` context. _ acts
// as a placeholder by default, allowing any combination of arguments to be
// pre-filled. Set `_.partial.placeholder` for a custom placeholder argument.
_.partial = restArgs(function(func, boundArgs) {
var placeholder = _.partial.placeholder;
var bound = function() {
var position = 0, length = boundArgs.length;
@AndreasLoukakis
AndreasLoukakis / Laravel Sentry 2 with multiple user types.md
Created November 19, 2016 15:55 — forked from leabdalla/Laravel Sentry 2 with multiple user types.md
Laravel Sentry 2 with multiple user types, finally.

Sentry is an amazing auth system. But I really need a feature: multiple user types in the same app. And I cannot separate those in groups, because they have different table columns. After 2 days burning my head, I think I found a good solution. The magic is duplicate SentryServiceProvider with new different settings.

This was tested on Laravel 4.0 and Sentry 2. If you're using other version of Sentry, my suggestion is to follow same steps from this gist but use your local files instead copying files from here.

Lets suppose we have a fresh Sentry install with default User ambient. Now we want another ambient called Admin, with new model and different settings. How to do:

1. One model, one ambient

@AndreasLoukakis
AndreasLoukakis / http-service.ts
Created November 13, 2016 11:21
Wrap Angular 2 http service with custom headers
import { Injectable} from '@angular/core';
import { Http, Headers, Response } from '@angular/http';
import { XCSRF } from './../services/tokens'
@Injectable()
export class HttpClient {
constructor(http: Http) {
this._http = http;
}
private _http: Http;
@AndreasLoukakis
AndreasLoukakis / amka.validator.ts
Created November 12, 2016 12:53
ΑΜΚΑ validator for angular2
import {AbstractControl} from '@angular/forms';
export class AmkaValidator {
public static validate(c:AbstractControl) {
let isElevenDigitNumber = /^\d{11}$/.test(c.value),
string_amka = c.value.toString(),
sumIsValid = false,
sum = 0;
@AndreasLoukakis
AndreasLoukakis / form.php
Created January 23, 2016 18:03
vue directive for ajax submits on laravel
<form method="POST"
action="/posts/3"
v-ajax complete="Okay, the post has been deleted."
>
{{ method_field('DELETE') }}
{{ csrf_field() }}
<button type="submit">Delete Post</button>
</form>

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called Reactive Programming, particularly its variant comprising of Rx, Bacon.js, RAC, and others.

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

const combine = (...arrays)
=> [].concat(...arrays);
const compact = arr
=> arr.filter(Boolean);
const contains = (() => Array.prototype.includes
? (arr, value) => arr.includes(value)
: (arr, value) => arr.some(el => el === value)
)();