Skip to content

Instantly share code, notes, and snippets.

View ldiego08's full-sized avatar

Luis Aguilar ldiego08

View GitHub Profile
alert('Custom experience.');
@ldiego08
ldiego08 / user-roles.gql
Last active August 9, 2018 17:25
Layman GQL - User Roles Query
query {
user(id: 2) {
id
login
roles { # also fetch roles
id # .. and their id
name # .. and their name
}
}
}
@ldiego08
ldiego08 / components.tsx
Last active June 13, 2018 03:25
State Management - Components
import React, { Component } from 'react';
export interface HeaderProps {
searchBoxProps: SearchBoxProps;
}
export class Header extends Component<HeaderProps> {
render() {
return (
<div>
@ldiego08
ldiego08 / 1-store.ts
Last active July 5, 2018 14:31
State Management - MST
import { flow, types } from 'mobx-state-tree';
export const TagsStoreModel = types
.model('TagsStore', {
results: types.array(types.string),
isLoading: types.boolean,
query: types.string,
})
.actions((self) => ({
loadTags: flow(function * (query: string) {
@ldiego08
ldiego08 / 1-store.ts
Created June 13, 2018 03:21
State Management - MobX
import { observable, action, extendObservable } from 'mobx';
export class TagsStore {
private static defaultState: any = {
query: '',
isLoading: false,
results: [],
};
@observable public results: string[];
@ldiego08
ldiego08 / 1-actions.ts
Last active June 13, 2018 03:05
State Management - Redux
import { Action } from 'redux';
export enum TagActions {
Search = 'TAGS_SEARCH',
SearchUpdate = 'TAGS_SEARCH_UPDATE',
SearchError = 'TAGS_SEARCH_ERROR',
}
export interface TagsSearchAction extends Action {
type: TagActions.Search;
@ldiego08
ldiego08 / header.ts
Created June 8, 2018 00:21
State Management - Redux vs MobX vs MST
interface HeaderProps {
searchBoxProps: SearchBoxProps;
}
class Header extends Component<HeaderProps> {
render() {
return (
<div>
<SearchBox {...this.props.searchBoxProps} />
</div>
@ldiego08
ldiego08 / app.js
Created April 10, 2014 03:47
JSApps 101: Basic AngularJS Data Binding
var toDoListApp = angular.module('ToDoListApp', []);
toDoListApp.controller('ToDoListController', function ($scope) {
/* Model */
$scope.items = [
{desc: 'Go shopping', done: false},
{desc: 'Clean my room', done: true},
{desc: 'Sleep', done: false}
@ldiego08
ldiego08 / ListQuery.cs
Created March 20, 2013 21:30
Sample implementation of some LINQ methods.
using System;
using System.Collections.Generic;
namespace Codenough.Demos.MapReduce
{
public static class ListQuery
{
public delegate bool Comparator<TSource>(TSource current, TSource target);
public delegate TAccumulate Aggregator<TSource, TAccumulate>(TSource current, TAccumulate value);
@ldiego08
ldiego08 / DeferredStream.cs
Last active December 14, 2015 02:49
Example of infinite streams of numbers and the Sieve of Erathostenes using functional programming in C#. Adapted from an example written by Edwin Dalorzo (https://gist.github.com/edalorzo/5015143)
using System;
namespace Codenough.Samples
{
public class DeferredStream<TValue> : IStream<TValue>
{
private readonly TValue head;
private readonly Func<IStream<TValue>> tail;
public DeferredStream(TValue head, Func<IStream<TValue>> tail)