Skip to content

Instantly share code, notes, and snippets.

View wildeyes's full-sized avatar
🎯
Focusing

wildeyes wildeyes

🎯
Focusing
  • TLV
View GitHub Profile
@wildeyes
wildeyes / jsonify.location.search.jsx
Last active June 24, 2016 12:43
ES 6 snippet to extract and convert the query/search string from location to a JSON object
String.prototype.remove = function(str) { return this.replace(str, ''); };
String.prototype.surround = function(char, char2=char) { return char + this + char2; };
// String.prototype.print = function() { console.log(this); return this; };
foo = location.search
.remove('?')
.split('&')
.map(exp => exp.split('=').map(str => str.surround('"')).join(':').surround('{', '}'))
// .print()
.join(',')
@wildeyes
wildeyes / Enhance.js
Created August 11, 2016 08:41 — forked from sebmarkbage/Enhance.js
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@wildeyes
wildeyes / subl-fix-path.ps1
Created February 5, 2017 16:44
Script to add sublime text 3 to environment path variable permanently via powershell (Administrator)
# Run with administrator rights,
# you can simply copy and paste into a powershell session
$PATH = [Environment]::GetEnvironmentVariable("PATH");
$subl = "C:\Program Files\Sublime Text 3";
[Environment]::SetEnvironmentVariable("PATH", "$PATH;$subl", "Machine");
refreshenv;
@wildeyes
wildeyes / global.d.ts
Created July 29, 2017 18:48
Global d.ts stuff
declare module '*.icss' {
const styles: {
[className: string]: string
};
export default styles;
}
@wildeyes
wildeyes / require.js
Created August 17, 2017 13:45
Load into the browser's console (dev tools) any npm package
// Add a require function that works just like in node, but can require any npm package, with it's version too.
// example 1 : require('lodash'); instanceof window.lodash === 'object'
function require(npmModule) {
console.info(`Attempting to load ${npmModule}...`);
var version = npmModule.indexOf('@') !== -1 ? '' : '@latest';
var body = document.getElementsByTagName('body')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = `https://wzrd.in/standalone/${npmModule}${version}`;
script.onload = () => console.log(`Loaded ${npmModule}!`)
@wildeyes
wildeyes / annotation-example.ts
Last active September 27, 2017 07:48
How to annotate X in typescript
// The Typescript language spec, https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md, is the definitive guide for
// how to annotate a react class, or anything else. But, sometimes, examples with a lot of SEO compatible words is better.
// Annotate a decorator that takes a react class, and wraps it. It'll have the same props as it's child.
export const decorateWithX = <T extends {}>(Comp: ComponentClass<T>): ComponentClass<T> => class extends PureComponent<T, State> {
}
// https://github.com/Microsoft/TypeScript/issues/4922
@wildeyes
wildeyes / Switch.elm
Created September 30, 2017 15:35
The Elm Switch (Case Of) Statement + Destructuring (Pattern Matching)
type User
= Activated
| Deleted
update state =
case state of
Activated ->
-- do something
Deleted ->
-- do again
@wildeyes
wildeyes / Types.elm
Created September 30, 2017 15:41
Elm Types (Akin to Classes, only simpler)
sadf
@wildeyes
wildeyes / gotcha,elm
Created October 4, 2017 08:14
Beginner Elm (Or simply functional programming) Gotchas
-- Functions are curried, that means when a function is called with not enough arguments, we don't get an "argument error exception", but a NEW function, that expects the remaining amount of arguments.
-- This can lead to some cryptic-for-beginners compiler type errors.
@wildeyes
wildeyes / lies-i-tell-you.lies.ts
Created October 24, 2017 11:13
Lying to the typesystem
// const getPortfoliosSync = createActionWithoutAlsoTyingDispatch(() => ({}));
const createActionWithoutAlsoTyingDispatchAsync = <T>(getMeAPromise: () => Promise<T>) => {
const retValue: any = () => {
return;
};
return retValue as Promise<T>;
};
const getPortfoliosAsync = createActionWithoutAlsoTyingDispatchAsync(() => Promise.resolve(1));