Skip to content

Instantly share code, notes, and snippets.


Ahmed El Gabri ahmedelgabri

Block or report user

Report or block ahmedelgabri

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View *


There's no way to <link rel=preload> a Web Worker. This fixes that.

npm i -S gist:developit/567dde2346d785b2628224fddbf6783c

<!-- workers are now just a normal script preload: -->
<link rel=preload href=/path/to/worker.js as=script crossorigin>
View work-load-balance.js
const work = (() => {
let workload = []
let cursor = null
setImmediate(async () => {
while (true) {
const workload = await next()
// implement as much as possible outside the loop
for (const { context, args, resolve, reject } of workload) {
View church-numerals.js
// Y Combinator
const Y = a => (b => b (b)) (b => a (c => b (b) (c)))
// isomorphic Church encoding/decoding
const Church = {
to: n => f => x => Array.from (Array (n)).reduce (f, x),
from: f => f (x => x + 1) (0)
const True = a => b => a

Everything I Know About UI Routing


  1. Location - The location of the application. Usually just a URL, but the location can contain multiple pieces of information that can be used by an app
    1. pathname - The "file/directory" portion of the URL, like invoices/123
    2. search - The stuff after ? in a URL like /assignments?showGrades=1.
    3. query - A parsed version of search, usually an object but not a standard browser feature.
    4. hash - The # portion of the URL. This is not available to servers in request.url so its client only. By default it means which part of the page the user should be scrolled to, but developers use it for various things.
    5. state - Object associated with a location. Think of it like a hidden URL query. It's state you want to keep with a specific location, but you don't want it to be visible in the URL.

Teaching the practically useful parts of computer science

I think the practically useful parts of computer science could easily be taught via a book (or similar).

General considerations:

  • I think I only every really learned abstract concepts when I could play with them via a programming language. For example:
    • Logic via Prolog
    • Rewrite rules via Maude
lizthegrey / attributes.rb
Last active Aug 17, 2019
Hardening SSH with 2fa
View attributes.rb
default['sshd']['sshd_config']['AuthenticationMethods'] = 'publickey,keyboard-interactive:pam'
default['sshd']['sshd_config']['ChallengeResponseAuthentication'] = 'yes'
default['sshd']['sshd_config']['PasswordAuthentication'] = 'no'
bvaughn / example.jsx
Last active Aug 1, 2019
Advanced example for manually managing subscriptions in an async-safe way using hooks
View example.jsx
import React, { useMemo } from "react";
import useSubscription from "./useSubscription";
// In this example, "source" is an event dispatcher (e.g. an HTMLInputElement)
// but it could be anything that emits an event and has a readable current value.
function Example({ source }) {
// In order to avoid removing and re-adding subscriptions each time this hook is called,
// the parameters passed to this hook should be memoized.
const subscription = useMemo(
() => ({
OliverJAsh / _git-merge-pr
Last active Mar 6, 2019
`git merge-pr`: CLI for merging GitHub PRs (via API) with completions
View _git-merge-pr
#compdef git-merge-pr
_git-merge-pr () {
# Note: requires hub and jq to be installed
# hub api /repos/{owner}/{repo}/pulls
hub api /repos/{owner}/{repo}/pulls \
| jq 'map({title, number, head})'
necolas / createOrderedCSSStyleSheet.js
Last active Jan 26, 2019
OrderedCSSStyleSheet: control the insertion order of CSS
View createOrderedCSSStyleSheet.js
* Copyright (c) Nicolas Gallagher.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @flow strict-local
type Groups = { [key: number]: Array<string> };
OliverJAsh / foo.tsx
Last active Jul 18, 2019
TypeScript React HOC using `forwardRef`
View foo.tsx
import * as React from 'react';
import { Component, ComponentClass, createRef, forwardRef, Ref } from 'react';
const myHoc = <ComposedComponentProps extends {}>(
ComposedComponent: ComponentClass<ComposedComponentProps>,
) => {
type ComposedComponentInstance = InstanceType<typeof ComposedComponent>;
type WrapperComponentProps = ComposedComponentProps & {
wrapperComponentProp: number;
You can’t perform that action at this time.