Skip to content

Instantly share code, notes, and snippets.

View jensen's full-sized avatar

Karl Jensen jensen

View GitHub Profile
@jensen
jensen / holidayobfuscation.js
Created December 22, 2017 21:24 — forked from krsnachandra/holidayobfuscation.js
Submission for LHL holiday obfuscation contest
function g() {
let a='Noel';
let b='Yuletide';
let c='Santa Claus';
let d='Rudolph';
let e='Snowflake';
let f='Occasion';
let g='North Pole';
let h='Christmas Tree';
let i='Joy';
@jensen
jensen / add-requests.js
Created April 7, 2020 20:46
Example of some React Testing
import React from "react";
import { render, fireEvent } from "@testing-library/react";
import { AddMethod } from "components/request/method";
describe("Adding Requests", () => {
it("should call addRequest with GET when the plus button is clicked", () => {
const addRequestMock = jest.fn();
const { getByTitle } = render(<AddMethod addRequest={addRequestMock} />);
@jensen
jensen / data.js
Created April 10, 2020 01:27
A sample data structure for a questionaire application
const readings = [
{
id: 1,
conversation: ['A long paragraph for someone to read...', 'Another line'],
question: [
{
question: 'What was this thing about?',
answer: [
{ text: 'The moon', correct: false },
{ text: The stars', correct: true },
@jensen
jensen / OrderedTable.vue
Created April 10, 2020 19:20
Example of data loading in an ordered table
<template>
<div>
<md-table v-model="players" :table-header-color="tableHeaderColor">
<md-table-row slot="md-table-row" slot-scope="{ item }">
<md-table-cell md-label="Name">{{ item.player }}</md-table-cell>
<md-table-cell md-label="Completed">{{
item.mCompleted
}}</md-table-cell>
<md-table-cell md-label="Records">{{ item.mRecords }}</md-table-cell>
<md-table-cell md-label="Points">{{ item.points }}</md-table-cell>
@jensen
jensen / TopNavbar.vue
Created April 10, 2020 19:21
Example of how to do a redirect on autocomplete search
<template>
<md-toolbar md-elevation="0" class="md-transparent">
<div class="md-toolbar-row">
<div class="md-toolbar-section-start">
<h3 class="md-title">{{ $route.name }}</h3>
</div>
<div class="md-toolbar-section-end">
<md-button
class="md-just-icon md-simple md-toolbar-toggle"
:class="{ toggled: $sidebar.showSidebar }"
@jensen
jensen / server.js
Created April 10, 2020 20:49
Example of endpoints for questions and answers
const express = require("express");
const app = express();
const bodyparser = require("body-parser");
const conversations = [
{
id: "1e14ace4-7807-42a0-b542-9b99798526d2",
conversation: ["Hey man", "Hey whats up?", "Nothing much", "Oh thats cool"],
questions: [
{
@jensen
jensen / index-react.html
Created April 10, 2020 23:04
Updated server code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Conversations</title>
<meta name="description" content="" />
<meta name="author" content="" />
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script
crossorigin
@jensen
jensen / client.js
Created April 12, 2020 22:49
Example websocket server/client with broken reconnect, fix it!
"use strict";
let websocket = require("websocket");
let url = "ws://localhost:8080";
let wsBitMex = new websocket.client();
let retries = 0;
function retryConnection() {
if (retries < 3) {
setTimeout(() => {
@jensen
jensen / math.html
Created April 13, 2020 19:44
How to use decimal.js library for more precision
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>MathJS</title>
<meta name="description" content="MathJS" />
<meta name="author" content="jenskarlsen" />
<script src="./js/decimal.js"></script>
<script>
Decimal.set({ precision: 30 });
@jensen
jensen / example.js
Created April 14, 2020 21:11
Example of refactoring into functions
/* this function process and object x of the pair in parameters, and add this data to the existing data of the current 0 to 30sec interval.
after the 30 sec pass, a timeout will get the bmBuffer[pair].data and send it elsewhere, there as a constant. perhaps, but bmBuffer is a global let */
let bmBuffer = {};
function bmProcessPayload(x, pair) {
if (bmCfg.consoled.trade) {
consoled("trade", bmAutobotPayload(x, pair));
}
bmBuffer[pair].data.timestamp = new Date(x.timestamp);