Skip to content

Instantly share code, notes, and snippets.

Manuel Alabor swissmanu

Block or report user

Report or block swissmanu

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
@swissmanu
swissmanu / stacktrace.js
Last active Jun 12, 2019
Revive a JavaScript stacktrace string with local available source maps.
View stacktrace.js
const fs = require('fs');
const retrace = require('retrace'); // yarn add retrace
const path = require('path');
retrace.resolve = uri => {
// assumes that source maps are in the same directory as this script, but in
// a `maps` folder:
return readFile(path.join(__dirname, 'maps', `${path.basename(uri)}.map`));
};
View SketchSystems.spec
Editable Page
Error
Reset -> View
View*
Read
Change Data -> WaitForEdit
WaitForEdit
Ready -> Edit
Error -> Error
Edit
@swissmanu
swissmanu / apply-prettier.ts
Created Mar 21, 2019
Apply Prettier Schematic
View apply-prettier.ts
import { Rule, Tree } from '@angular-devkit/schematics';
import * as prettier from 'prettier';
import { Observable } from 'rxjs';
export default function(): Rule {
return (tree: Tree) =>
new Observable<Tree>(o => {
prettier.resolveConfig(process.cwd()).then(prettierConfig => {
if (!prettierConfig) {
o.error(new Error('Could not resolve prettier configuration'));
View SketchSystems.spec
Button
Disabled
enable -> Enabled
Enabled*
disable -> Disabled
Inactive
focus -> Active
mouseEnter -> Hovered
View typed-inputs-sketch.tsx
function Input<T>({
value,
onChange,
children,
serialize,
deserialize
}: {
value: T;
deserialize: (value: T) => string | null;
serialize: (rawValue: string | null) => T;
View headers
< HTTP/1.1 302 Found
< Content-Length: 34
< Content-Type: text/html; charset=utf-8
< Date: Wed, 05 Dec 2018 09:32:46 GMT
< Location: /user/login
< Set-Cookie: lang=en-US; Path=/; Max-Age=2147483647
< Set-Cookie: i_like_gogs=346ffxxxxxxxae8b; Path=/; HttpOnly
< Set-Cookie: _csrf=Pka0s5RZO-QhdGetTwxxxxxxxxxxNjcxxxxxxx3D%3D; Path=/; Expires=Thu, 06 Dec 2018 09:32:46 GMT; HttpOnly
< Set-Cookie: redirect_to=%252Fuser%252Frepos; Path=/
@swissmanu
swissmanu / WithState.tsx
Last active Sep 11, 2018
A wrapper component providing state to a stateless React component in TypeScript.
View WithState.tsx
// setState signature borrowed from react 😇
interface WithStateProps<S> {
initialState: S;
children: (
state: S,
setState: <K extends keyof S>(
state: ((prevState: Readonly<S>, props: {}) => Pick<S, K> | S | null) | (Pick<S, K> | S | null),
callback?: () => void
) => void
) => React.ReactChild;
View graph.json
{
"data": [
{
"id": {
"@type": "g:Int64",
"@value": 12336
},
"label": "vertex",
"inE": {
"relates": [
@swissmanu
swissmanu / eventually.ts
Last active Feb 15, 2018
Typed eventually construct using TypeScript and Promises
View eventually.ts
// Example Usage:
eventually(20)(() => fetch('http://i.fail.often.com/data.json'))
.then(data => console.log(data))
.catch(e => console.log(e));
function eventually<T>(
giveUpAfterNumberOfRetries: number,
nextInterval: (numberOfRetries: number) => number = linearRetryInterval
) {
@swissmanu
swissmanu / functional.js
Last active Dec 7, 2017
Array juggling in JavaScript with functional programming approach
View functional.js
// precondition: xs is always an array
function head(xs) {
if (xs.length === 0) return null
return xs[0]
}
function tail(xs) {
return xs.slice(1)
}
You can’t perform that action at this time.