Parallelization made easy in JavaScript / Node.js
var road = new Road();
road.onClear(function (error, results) {
# Fish git prompt | |
set __fish_git_prompt_showdirtystate 'yes' | |
set __fish_git_prompt_showstashstate 'yes' | |
set __fish_git_prompt_showupstream 'yes' | |
set __fish_git_prompt_color_branch yellow | |
# Status Chars | |
set __fish_git_prompt_char_dirtystate '⚡' | |
set __fish_git_prompt_char_stagedstate '→' | |
set __fish_git_prompt_char_stashstate '↩' |
// Concurrent.go | |
// Simple example that demonstrates usage of Go routines. | |
package main | |
import ( | |
"fmt" | |
"time" | |
"math/rand" | |
) |
function getBrowser() { | |
var nVer = navigator.appVersion; | |
var nAgt = navigator.userAgent; | |
var browserName = navigator.appName; | |
var fullVersion = '' + parseFloat(navigator.appVersion); | |
var majorVersion = parseInt(navigator.appVersion, 10); | |
var nameOffset, verOffset, ix; | |
// In Opera, the true version is after "Opera" or after "Version" | |
if ((verOffset = nAgt.indexOf("Opera")) != -1) { |
#!/usr/bin/env node | |
/** | |
* A little script to play the ASCII Star Wars, but with a hidden cursor, | |
* since over `telnet(1)` the cursor remains visible which is annoying. | |
*/ | |
process.title = 'starwars' | |
var net = require('net') |
Let's close the ultra-small library cycle with some awesome array-based templating. 323 bytes minified.
Just download the minified version here or include it into your code:
$.ajax({ | |
url: 'MASHAPE-URL', // The URL to the API. You can get this by clicking on "Show CURL example" from an API profile | |
type: 'POST', // The HTTP Method | |
data: {}, // Additional parameters here | |
dataType: 'json', | |
success: function(data) { alert(JSON.stringify(data)); }, | |
error: function(err) { alert(err); }, | |
beforeSend: function(xhr) { | |
xhr.setRequestHeader("X-Mashape-Authorization", "YOUR-MASHAPE-KEY"); // Enter here your Mashape key | |
} |
<!DOCTYPE html> | |
<head> | |
<title>salary: submit info</title> | |
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/base-min.css"> | |
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<style> | |
body { | |
padding: 1em; | |
} |
I used this structure in multiple projects and had a blast using it which is why I want to share it. It automatically propagates state changes to all dependent states and does not require additional state managing packages such as redux or mobx.
It enables architectures where e.g. the navbar is at the same level as all other components while still receiving updates about e.g. current user: If in this example the Index View logs the user in, there will also be a re-render in the navbar as its state has changed. This construction removes the state-silos of each component. Using useState
instead of useReflectedState
still enables the usage of component-specific state.
import React from "react";
import ReactDOM from "react-dom";
import { BrowserRouter as Router, Route } from "react-router-dom";
import Navbar from "./views/Navbar";
import Index from "./views/Index";