Skip to content

Instantly share code, notes, and snippets.

View fijiwebdesign's full-sized avatar

Gabirieli Lalasava fijiwebdesign

View GitHub Profile
@fijiwebdesign
fijiwebdesign / inline-shared-webworker-example.js
Last active February 12, 2017 09:56
Shared WebWorker example
/**
* Shared Web Worker
* see: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
* https://www.sitepoint.com/javascript-shared-web-workers-html5/
*/
// note: we can't share this webworker from another tab or window.
// since window.URL.createObjectURL() creates URL refs in the scope of the local window/tab
// inline our file
@fijiwebdesign
fijiwebdesign / mixin-hoc.js
Last active February 10, 2017 18:17
React HOC example from React Docs
/**
* What about a HOC that has multiple mixins
* The HOC if flattened from mixins
* The WrappedComponent is still decoupled from HOC
* todo: test
*/
function mixinHoc(WrappedComponent, mixins) {
mixins = [].concat(mixins)
@fijiwebdesign
fijiwebdesign / templating.js
Created December 10, 2016 08:39 — forked from asuh/templating.js
JS templating system
'use strict';
/*
* Javascript templating system
*/
$(document).ready(function() {
function loadTemplate(element, path, callback, done) {
$.ajax(path).then(function(html) {
element.append(html);
if (typeof callback === 'function' ) {
const http = require('http');
let server = http.createServer();
server.on('request', (request, response) => {
let {method, url, headers} = request;
console.log(`Received ${method} request for "${url}".`);
for (let headerName of Object.keys(headers)) {
let headerValue = headers[headerName];
@fijiwebdesign
fijiwebdesign / object-keys.js
Created June 28, 2016 23:49
Keys of an Object
// object
var Person = {
name: 'mr smith',
profession: 'dandy fella',
age: 10000
}
// array of keys of Person
var properties = Object.keys(Person);
console.log(properties); // ['name', 'profession', 'age']
@fijiwebdesign
fijiwebdesign / local-object-properties.js
Created June 28, 2016 23:45
JS local object properties test
// test local and inherited properties of an object
var obj = { name: 'test' };
console.log(obj.name); // 'test'
console.log(obj.hasOwnProperty('name')); // true
obj.__proto__.age = 10000; // hack to make age an inherited property
console.log(obj.age); // 10000
console.log(obj.hasOwnProperty('age')); // false
@fijiwebdesign
fijiwebdesign / object-iteration-for-in.js
Last active June 29, 2016 00:05
Object keys iteration with forEach
// iteration using for..in loop and hasOwnProperty
var Person = {
name: 'mr smith',
profession: 'dandy fella',
age: 10000,
reset: function() {
for (var prop in this) {
if (prop == 'reset' || !this.hasOwnProperty(prop)) {
console.log("leave it alone", prop)
@fijiwebdesign
fijiwebdesign / xdate.js
Last active April 28, 2016 10:05
Extend native Date prototype without affecting the Date object
// based on http://stackoverflow.com/a/30882416/255239
function XDate() {
// create new Date() with passed in args
var date = new (Function.prototype.bind.apply(Date, [Date].concat(Array.prototype.slice.call(arguments))))
date.__proto__ = XDate.prototype; // make XDate.prototype the inherited prototype of our Date instance.
return date;
}
XDate.prototype.__proto__ = Date.prototype; // inherit Date prototype so we can use Date methods
@fijiwebdesign
fijiwebdesign / csv-parsing.php
Created August 4, 2015 14:58
Parsing a CSV file - sorting and aggregating entries
<?php
$filename = './Voters_for_SDC4CRetriever_Official-groupby-email.csv';
$name = null;
$entry_fp = null;
$entry_arr = [];
$fp = fopen($filename, 'r');
while (true) {
@fijiwebdesign
fijiwebdesign / git-fork-sync-with-original.txt
Last active August 29, 2015 14:13
Git fork a repo and keep updated with original repo
# **fork repo via github UI**
# clone locally
git clone <repo-location>
# add a remote called "upstream" pointing to original repo location
git remote add upstream <repo-location>
# now you have two remotes, "origin" which is the forked repo and "upstream" which is the original