Skip to content

Instantly share code, notes, and snippets.

View moatorres's full-sized avatar
👋

Moa Torres moatorres

👋
  • 23:47 (UTC -03:00)
View GitHub Profile
@sebmarkbage
sebmarkbage / Infrastructure.js
Last active February 26, 2025 13:57
SynchronousAsync.js
let cache = new Map();
let pending = new Map();
function fetchTextSync(url) {
if (cache.has(url)) {
return cache.get(url);
}
if (pending.has(url)) {
throw pending.get(url);
}
// safe objects won't throw when trying to get a
// property which doesn't exist.
const safe = value => new Proxy({
extract() {
return value
}
}, {
get(obj, key) {
return key === 'extract'
const State = state => new Proxy({
state,
listeners: [],
subscribe(listener) {
this.listeners.push(listener)
return () => this.listeners.filter(x => x !== listener)
},
set(stateUpdates) {
this.state = Object.assign({}, this.state, stateUpdates);
this.listeners.forEach(f => {
@jaredpalmer
jaredpalmer / App.js
Created May 30, 2017 17:45
Next.js-like SSR without Next.js.
import React from 'react';
import Route from 'react-router-dom/Route';
import Link from 'react-router-dom/Link';
import Switch from 'react-router-dom/Switch';
const App = ({ routes, initialData }) => {
return routes
? <div>
<Switch>
{routes.map((route, index) => {
@gvergnaud
gvergnaud / lazy-list.js
Last active September 13, 2024 23:03
Lazy List, implemented with es6 generators
/* ----------------------------------------- *
Lazy List Implementation
* ----------------------------------------- */
// Haskell-like infinite List, implemented with es6 generators
// Lazyness lets you do crazy stuff like
List.range(0, Infinity)
.drop(1000)
.map(n => -n)
@gvergnaud
gvergnaud / Task.js
Last active June 27, 2021 19:34
Task.js — Full Implementation (SemiGroup, Monoid, Functor, Monad, Applicative)
import { compose, add, map, range } from 'lodash/fp'
import { Just, Nothing } from './Maybe'
class Task {
constructor(fork) {
this.fork = fork
}
static of(x) {
return Task.resolve(x)
@bennadel
bennadel / cache.js
Created March 9, 2015 11:56
Creating Objects With A Null Prototype In Node.js
// In this version of the cache, we're going to use an internal object with a null
// prototype and then assume that no user-provided cache keys will ever conflict with
// native keys.
function SafeCache() {
var cache = Object.create( null );
// Reveal the public API.
return({
get: get,
@mik01aj
mik01aj / gulpfile.js
Created February 10, 2015 12:10
A hackish way to re-run tests just for the changed file. (Gulp + Jest)
// ... requires, initialization and stuff ...
function runJest(changedFilePath) {
var nodeModules = path.resolve('./node_modules');
var jestConfig = {
scriptPreprocessor: nodeModules + '/gulp-jest/preprocessor.js',
unmockedModulePathPatterns: [nodeModules + '/react'],
moduleFileExtensions: ['js', 'jsx'],
testFileExtensions: ['js', 'jsx'],
};
@myusuf3
myusuf3 / delete_git_submodule.md
Created November 3, 2014 17:36
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
@natelandau
natelandau / .bash_profile
Last active April 25, 2025 02:45
Mac OSX Bash Profile
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management