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 / Types.elm
Created September 30, 2017 15:41
Elm Types (Akin to Classes, only simpler)
sadf
@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 / 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 / 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 / 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 / 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 / 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 / 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 / load.js
Created May 14, 2016 20:43
Async Script Loading in Browser Javascript Snippet
(function(url) {
var scriptTag = document.createElement('script');
scriptTag.type = 'text/javascript';
scriptTag.async = true;
scriptTag.src = url;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(scriptTag, s);
})(URL);
@wildeyes
wildeyes / polyfills.coffee
Created December 14, 2015 08:30
My favourite, essential " polyfills " for projects with coffeescripts.
# xxx turn this into a bower/npm module
Object.defineProperty Array.prototype, "last", { get: -> this[this.length - 1]}
Object.defineProperty Array.prototype, "first", { get: -> this[0]}
Function::property = (prop, desc) ->
Object.defineProperty @prototype, prop, desc
Function::getter = (prop, get) ->
Object.defineProperty @prototype, prop, {get, configurable: yes}
Function::setter = (prop, set) ->
Object.defineProperty @prototype, prop, {set, configurable: yes}