Skip to content

Instantly share code, notes, and snippets.

@kenjox
kenjox / handlers_test.go
Created February 26, 2020 08:46 — forked from p4tin/handlers_test.go
Testing Http Handlers in GO
package main
import (
"net/http"
"testing"
"net/http/httptest"
)
func TestHealthCheckHandler(t *testing.T) {
// Create a request to pass to our handler. We don't have any query parameters for now, so we'll
@kenjox
kenjox / Enhance.js
Created January 18, 2019 09:49 — 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() {
@kenjox
kenjox / mashupEnigmaRequire.js
Created October 2, 2018 07:03 — forked from ralfbecher/mashupEnigmaRequire.js
Qlik Sense Mashup with Enigma.js - the official way
var prefix = window.location.pathname.substr(0, window.location.pathname.toLowerCase().lastIndexOf("/extensions") + 1);
var config = {
host: window.location.hostname,
prefix: prefix,
port: window.location.port,
isSecure: window.location.protocol === "https:"
};
require.config({
baseUrl: (config.isSecure ? "https://" : "http://") + config.host + (config.port ? ":" + config.port : "") + config.prefix + "resources"
});
@kenjox
kenjox / service-workers.md
Created September 5, 2018 13:56 — forked from Rich-Harris/service-workers.md
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

@kenjox
kenjox / eslint.json
Created August 12, 2018 07:46 — forked from BilalBudhani/eslint.json
Wesbos' eslint + prettier config
{
"extends": [
"airbnb",
"prettier",
"prettier/react"
],
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 8,
"ecmaFeatures": {
@kenjox
kenjox / cpu.js
Created July 1, 2018 08:11 — forked from bag-man/cpu.js
How to calculate the current CPU load with Node.js; without using any external modules or OS specific calls.
var os = require("os");
//Create function to get CPU information
function cpuAverage() {
//Initialise sum of idle and time of cores and fetch CPU info
var totalIdle = 0, totalTick = 0;
var cpus = os.cpus();
//Loop through CPU cores
@kenjox
kenjox / client.js
Created June 29, 2018 10:20 — forked from crtr0/client.js
A simple example of setting-up dynamic "rooms" for socket.io clients to join
// set-up a connection between the client and the server
var socket = io.connect();
// let's assume that the client page, once rendered, knows what room it wants to join
var room = "abc123";
socket.on('connect', function() {
// Connected, let's sign-up for to receive messages for this room
socket.emit('room', room);
});
@kenjox
kenjox / index.html
Created May 18, 2018 00:12 — forked from tpluscode/index.html
Importing and stamping templates with ES6 and lit-html
<!DOCTYPE html>
<html lang="en">
<body>
<vanilla-lit tagline="Luke"></vanilla-lit>
<script src="bundle.js"></script>
</body>
</html>
@kenjox
kenjox / README.md
Created February 2, 2018 07:52 — forked from joyrexus/README.md
Vanilla JS equivalents of jQuery methods

Sans jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@kenjox
kenjox / nativeJavaScript.js
Created January 25, 2018 20:36 — forked from alexhawkins/nativeJavaScript.js
Implementation of Native JavaScript Methods (forEach, Map, Filter, Reduce, Every, Some)
'use strict';
/*****************NATIVE forEACH*********************/
Array.prototype.myEach = function(callback) {
for (var i = 0; i < this.length; i++)
callback(this[i], i, this);
};
//tests