Skip to content

Instantly share code, notes, and snippets.

View jensen's full-sized avatar

Karl Jensen jensen

View GitHub Profile
@jensen
jensen / klaviyo.ts
Created February 20, 2023 02:10
Adding profiles with Klaviyo API
const BASE_URL = "https://a.klaviyo.com/api";
const baseHeaders = new Headers({
accept: "application/json",
revision: "2023-01-24",
Authorization: `Klaviyo-API-Key ${process.env.KLAVIYO_API_KEY}`,
});
const getHeaders = new Headers(baseHeaders);
const postHeaders = new Headers(baseHeaders);
postHeaders.append("Content-Type", "application/json");
@jensen
jensen / graphql.gql
Created May 6, 2020 22:25
Song Container Relay Example
query SongsContainerQuery($count: Int!, $cursor: String) {
viewer {
...SongsContainer_viewer
}
}
fragment SongsContainer_viewer on Query {
id
songs(first: $count, after: $cursor)
@connection(key: "SongsContainer_songs", filters: []) {
@jensen
jensen / gist:b34bbdfbc2d37cf671a72c5e18a53b06
Created April 29, 2020 22:33
Creating a custom cursor with vanilla JS
<div>?</div>
div {
position: absolute;
bottom: 0;
right: 0;
}
* {
cursor: none;
@jensen
jensen / wordgame.jsx
Created April 26, 2020 21:22
Word game reducer
import React, { useState, useEffect, useReducer } from "react";
import Word from "./components/Word";
import wordsLibrary from "./words";
const starsSpeed = { animation: "animStar 50s linear infinite" };
const reducer = (state, action) => {
const { type, payload } = action;
if (type === "addWord") {
@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);
@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 / 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 / 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 / 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 / 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 }"