Skip to content

Instantly share code, notes, and snippets.

@amogower
amogower / converts-webfont-to-base64.js
Created May 6, 2018 16:44 — forked from arielsalminen/converts-webfont-to-base64.js
Convert Google WOFF font to base64 format and inline to <head> of document
// Get binary file using XMLHttpRequest
function getBinary(file) {
var xhr = new XMLHttpRequest();
xhr.open("GET", file, false);
xhr.overrideMimeType("text/plain; charset=x-user-defined");
xhr.send(null);
return xhr.responseText;
}
// Base64 encode binary string
Verifying my Blockstack ID is secured with the address 1yJtpM1dKRx3Ls6XWk785iwrvCCi216od https://explorer.blockstack.org/address/1yJtpM1dKRx3Ls6XWk785iwrvCCi216od
@amogower
amogower / Base.js
Created February 19, 2018 14:56
Base Class for JavaScript Inheritance
/*
Base.js, version 1.1a
Copyright 2006-2010, Dean Edwards
License: http://www.opensource.org/licenses/mit-license.php
*/
var Base = function() {
// dummy
};
@amogower
amogower / index.js
Created February 12, 2018 15:44
Tribonacci Sequence with Recursion
function tribonacci(signature, n) {
if (n <= 3) {
return signature.length === 3 ? signature.slice(0, n) : signature;
}
const numbers = n < 3 ? signature.slice(0, n) : signature.slice(-3);
const sum = numbers.reduce((acc, curr) => acc + curr);
return tribonacci([...signature, sum], n - 1);
}
@amogower
amogower / .htaccess
Created February 4, 2018 18:03
HTML5 Boilerplate htaccess file
# Apache Server Configs v2.15.0 | MIT License
# https://github.com/h5bp/server-configs-apache
# (!) Using `.htaccess` files slows down Apache, therefore, if you have
# access to the main server configuration file (which is usually called
# `httpd.conf`), you should add this logic there.
#
# https://httpd.apache.org/docs/current/howto/htaccess.html
# ######################################################################
@amogower
amogower / private_object_properties_with_proxies.js
Last active January 18, 2018 19:43
Private object propertiesPrivate object properties with ES2015 Proxies // source https://jsbin.com/puxezu
'use strict';
function privateProps(obj, filterFunc) {
var handler = {
get: function get(obj, prop) {
if (!filterFunc(prop)) {
var value = Reflect.get(obj, prop);
// auto-bind the methods to the original object, so they will have unrestricted access to it via 'this'.
if (typeof value === 'function') {
value = value.bind(obj);
@amogower
amogower / updating_fork.md
Created December 27, 2017 15:44 — forked from CristinaSolana/gist:1885435
Keeping a fork up to date

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@amogower
amogower / pubsub.js
Created November 30, 2017 22:56
Javascript Pub/Sub
var events = (function(){
var topics = {};
var hOP = topics.hasOwnProperty;
return {
subscribe: function(topic, listener) {
// Create the topic's object if not yet created
if(!hOP.call(topics, topic)) topics[topic] = [];
// Add the listener to queue
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _assign = require('babel-runtime/core-js/object/assign');
var _assign2 = _interopRequireDefault(_assign);
function buildReduxContainer(ChildComponentClass, mapStateToProps) {
return class Container extends Component {
render() {
const { state } = this.context.store.getState();
const props = mapStateToProps(state);
return <ChildComponentClass {...this.props} {...props} />;
}
}