Skip to content

Instantly share code, notes, and snippets.

View moimikey's full-sized avatar
:shipit:
ship it

Michael Scott Hertzberg moimikey

:shipit:
ship it
View GitHub Profile
@moimikey
moimikey / fill-array.js
Created December 5, 2017 01:35
fill array with value of variable in javascript in 49 bytes
const o = { a: true };
[...Array(9)].map(Function.prototype.valueOf, o);
@moimikey
moimikey / whatis.js
Last active March 18, 2016 14:55
really simple javascript type detection
const assert = function (condition) {
if (condition !== true && condition !== false) {
throw new TypeError("Assertions should be only of booleans; you're writing your spec wrong.");
}
if (!condition) {
throw new Error("Specification-level assertion failure");
}
};
function whatIs(this$) {
@moimikey
moimikey / after.js
Last active June 5, 2023 04:50
object literals for redux reducers
// O(1)
const todo = (state, action) => {
const actions = {
ADD_TODO: () => {
return {
id: action.id,
text: action.text,
completed: false
}
},
@moimikey
moimikey / babel.md
Last active January 24, 2016 02:00
babel notes of wisdom
lib notes
babel-cli basically what you need always
babel-register this is only for dev or local use and not production or browser
babel-core only necessary if using babel programatically
babel-polyfill shims inconsistent browser functions like Array.from, etc.
babel-runtime only helps at a code level by optimizing babel helpers into a single runtime

use presets

@moimikey
moimikey / custom.php
Created December 30, 2015 18:22
thermal, pull custom & acf fields
<?php
function north_cast_api_data($content) {
if (is_numeric($content)) $content = intval($content);
else {
$unserialized_content = @unserialize($content);
// we got serialized content
if ($unserialized_content !== false) {
// make sure that integers are represented as such, instead of str
foreach ($unserialized_content as $fn => &$c) {
if (is_numeric($c)) $c = intval($c);
@moimikey
moimikey / promise.js
Created November 23, 2015 21:24
a promise in javascript for dummies
// promises != callbacks
function doSomeAction() {
// like $.ajax or $.getJSON from jQuery, fetch will similarly reach out to a remote/local
// destination over HTTP, return a Promise object (the result of the `window.fetch`) that
// we can listen to by simply chaining the `then` method, which is provided by the Promise
// object that is returned by `window.fetch`.
window.fetch(new Request('http://website.com/products.json')).then(function(response) {
imFinished(response)
})
}
@moimikey
moimikey / callback.js
Created November 23, 2015 20:51
a callback in javascript for dummies
// callbacks != promises
function doSomeAction() {
return true
}
function appleTree() {
return doSomeAction()
}
appleTree()
@moimikey
moimikey / index.js
Last active November 20, 2015 21:18
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var locale2 = require('locale2');
document.write(locale2);
/**
* Michael Scott Hertzberg <mshertzberg@gmail.com> (http://hertzber.gs)
*
* recursively check for set localStorage value every 100ms.
* this will also safely clear the timeout once found.
* can be used callback style or directly.
* functionally pure.
*/
function waitForLocalStorage(key, cb, timer) {
if (!localStorage.getItem(key)) return (timer = setTimeout(waitForLocalStorage.bind(null, key, cb), 100))
@moimikey
moimikey / cubic-bezier.js
Last active November 3, 2015 02:52
named easing/cubic bezier lookups
{
easeOutCubic: "cubic-bezier(.215,.61,.355,1)",
easeInOutCubic: "cubic-bezier(.645,.045,.355,1)",
easeInCirc: "cubic-bezier(.6,.04,.98,.335)",
easeOutCirc: "cubic-bezier(.075,.82,.165,1)",
easeInOutCirc: "cubic-bezier(.785,.135,.15,.86)",
easeInExpo: "cubic-bezier(.95,.05,.795,.035)",
easeOutExpo: "cubic-bezier(.19,1,.22,1)",
easeInOutExpo: "cubic-bezier(1,0,0,1)",
easeInQuad: "cubic-bezier(.55,.085,.68,.53)",