Skip to content

Instantly share code, notes, and snippets.

:shipit:
ship it

Michael Scott Hertzberg moimikey

:shipit:
ship it
Block or report user

Report or block moimikey

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
View rick-roll.js
var music, musicParse;
musicParse = function(f) {
return eval("for(var t=0,S='RIFF_oO_WAVEfmt " + atob('EAAAAAEAAQBAHwAAQB8AAAEACAA') + "data';++t<3e5;)S+=String.fromCharCode(" + f + ")");
};
music = function() {
var audio, formula;
formula = '(t<<3)*[8/9,1,9/8,6/5,4/3,3/2,0][[0xd2d2c8,0xce4088,0xca32c8,0x8e4009][t>>14&3]>>(0x3dbe4688>>((t>>10&15)>9?18:t>>10&15)*3&7)*3&7]&255';
audio = new Audio("data:audio/wav;base64," + (btoa(musicParse(formula))));
@moimikey
moimikey / deepFlat.js
Created Mar 31, 2019
deep flatten array in javascript
View deepFlat.js
export const deepFlat = (arr) => arr.flat(Infinity)
@moimikey
moimikey / README.md
Last active May 29, 2018
inline props as styled-component css
View README.md

@moimikey

Usage

// valid css properties in camelCase (checked by `css-key`)
const props = {
  gridColumnStart: ...,
  gridColumnEnd: ...,
@moimikey
moimikey / a.js
Created Jan 6, 2018
filter out only `on` event props from react component
View a.js
// ...
renderMenu() {
const { children, ...rest } = this.props || {};
// only store props that startWith `on` in case the parent component
// wants to send event callbacks down, for subsequent use.
const eventProps = Object.keys(rest)
.filter(key => key.substr(0, 2) === 'on') // if startsWith 'on' (ie. onMouseOver)
.reduce((obj, key) => Object.assign(obj, { [key]: rest[key] }), {});
// ...
@moimikey
moimikey / fill-array.js
Created Dec 5, 2017
fill array with value of variable in javascript in 49 bytes
View fill-array.js
const o = { a: true };
[...Array(9)].map(Function.prototype.valueOf, o);
@moimikey
moimikey / whatis.js
Last active Mar 18, 2016
really simple javascript type detection
View whatis.js
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 Jun 26, 2018
object literals for redux reducers
View after.js
// 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 Jan 24, 2016
babel notes of wisdom
View babel.md
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 Dec 30, 2015
thermal, pull custom & acf fields
View custom.php
<?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 Nov 23, 2015
a promise in javascript for dummies
View promise.js
// 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)
})
}
You can’t perform that action at this time.