Skip to content

Instantly share code, notes, and snippets.

View jakub-zawislak's full-sized avatar

Jakub Zawiślak jakub-zawislak

View GitHub Profile
@johanquiroga
johanquiroga / useUndoReducer.js
Last active December 14, 2023 08:52
Undo/Redo capability for any reducer using react hook `useReducer`
import { useReducer } from 'react';
const useUndoReducer = (reducer, initialState) => {
const undoState = {
past: [],
present: initialState,
future: []
};
const undoReducer = (state, action) => {
@stephanbogner
stephanbogner / index.js
Created March 7, 2018 22:17
Create tree structure from paths array
var paths = [
["Account"],
["Account", "Payment Methods"],
["Account", "Payment Methods", "Credit Card"],
["Account", "Payment Methods", "Paypal"],
["Account", "Emails"],
["Account", "Emails", "Main Email"],
["Account", "Emails", "Backup Email"],
["Account", "Devices"],
["Account", "Devices", "Google Pixel"],
@Glideh
Glideh / RolesType.php
Last active March 11, 2024 12:24
This is an example of how one could create a custom type for roles to add in a User form
<?php
namespace AdminBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
use Symfony\Component\Security\Core\Role\Role;
@focusaurus
focusaurus / A.elm
Created December 5, 2016 00:26
Decode JSON string enum into elm union type
module A exposing (..)
import Json.Decode as JD
import Json.Encode as JE
type alias User =
{ id : Int
, theme : Theme
}
@hipertracker
hipertracker / Language.elm
Created November 19, 2016 17:08
Elm decoders for nested JSON structures
module Models.Language exposing (..)
import Json.Decode exposing (int, string, decodeString, Decoder)
import Json.Decode.Pipeline exposing (decode, required)
type alias Language =
{ id : Int
, name : String
, label : String
@emilsoman
emilsoman / phoenix_to_umbrella
Last active April 12, 2024 11:26
How to move an existing phoenix app under an umbrella app
How to convert existing phoenix app to an umbrella app.
https://elixir-lang.slack.com/archives/phoenix/p1472921051000134
chrismccord [10:14 PM]
@alanpeabody yes, it's straightforward
[10:14]
1) mix new my_umbrella --umbrella
@mbostock
mbostock / .block
Last active July 27, 2023 08:06
Force-Directed Web Worker
license: gpl-3.0
height: 960
@renatomefi
renatomefi / multitail.conf
Last active July 11, 2020 15:49
Symfony 2 and 3 monolog color output with multitail
# Symfony 2, 3, 4 color scheme - aka monolog
# Usage: multitail -cS symfony logfile
# Inspired by: https://gist.github.com/Stubbs/9504462
colorscheme:symfony
cs_re:white,,bold:^\[....-..-.. ..:..:..\]
cs_re:cyan: .*\.(DEBUG):
cs_re:blue: .*\.(INFO|NOTICE):
cs_re:yellow: .*\.(WARNING):
cs_re:red: .*\.(ERROR|CRITICAL):
cs_re:red:(ERROR|CRITICAL)
@kottenator
kottenator / simple-pagination.js
Created July 13, 2015 20:44
Simple pagination algorithm
// Implementation in ES6
function pagination(c, m) {
var current = c,
last = m,
delta = 2,
left = current - delta,
right = current + delta + 1,
range = [],
rangeWithDots = [],
l;
@tentacode
tentacode / list.html.twig
Created October 15, 2012 12:23
Twig recursive macro
{% macro recursiveCategory(category) %}
<li>
<h4><a href="{{ path(category.route, category.routeParams) }}">{{ category }}</a></h4>
{% if category.children|length %}
<ul>
{% for child in category.children %}
{{ _self.recursiveCategory(child) }}
{% endfor %}
</ul>