Skip to content

Instantly share code, notes, and snippets.

View ivorpad's full-sized avatar
🇪🇸
Working from Spain

Ivor ivorpad

🇪🇸
Working from Spain
View GitHub Profile
// validate hmac in shopify
const queryString = ctx.request.url.split("?")[1];
const isHmacValid = valid.checkHmacValidity(
process.env.SHOPIFY_API_SECRET_KEY,
queryString
);
// TODO: Improve error handling
if (!isHmacValid) {
ctx.redirect("/auth");
@ivorpad
ivorpad / machine.js
Created September 1, 2020 12:19
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
function componentToHex(component) {
const hex = component.toString(16);
return hex.length === 1 ? `0${hex}` : hex;
}
function rgbFromHueAndChroma(hue, chroma) {
const huePrime = hue / 60;
const hueDelta = 1 - Math.abs((huePrime % 2) - 1);
const intermediateValue = chroma * hueDelta;
{"entity":{
"canCreateTemplate" : true,
"containers" : {
"//starter.dotcms.com/application/containers/default/" : {
"containerStructures" : [ {
"id" : "86a06a2e-ba40-43d4-a3ad-3a870d43bfc1",
"structureId" : "799f176a-d32e-4844-a07c-1b5fcd107578",
"containerInode" : "61f070f0-8def-4858-ab76-f22bcb6feaaa",
"containerId" : "69b3d24d-7e80-4be6-b04a-d352d16493ee",
"code" : "#dotParse(\"//starter.dotcms.com/application/containers/default/blog.vtl\")",
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
const generatePieChartData = (data, percentages = false, keys = []) => {
const isSingleArray = Object.keys(data).length <= 1;
if (isSingleArray) {
return Object.entries(data).reduce((acc, [key, data], idx) => {
keys.forEach((k, i) => {
acc[i] = {
id: k,
label: k,
value: data[i]
Object.entries(sample[0]).reduce((acc, [key, data], idx) => {
var keysObj = {}
keys.forEach((k, i) => {
keysObj[k] = typeof(data[i]) === "string" ? +data[i] : data[i];
});
const dataObj = {
dimension: key,
...keysObj
}
@ivorpad
ivorpad / machine.js
Last active February 27, 2020 18:32
Generated by XState Viz: https://xstate.js.org/viz
const actionSheet = Machine({
id: 'actionSheet',
initial: 'idle',
context: {
results: []
},
states: {
idle: {
on: {
SELECT: 'loading',
@ivorpad
ivorpad / machine.js
Last active February 27, 2020 00:32
Generated by XState Viz: https://xstate.js.org/viz
const connectedMachine = Machine({
id: 'connectedData',
initial: 'idle',
context: {
results: []
},
states: {
idle: {
on: {
ADD: 'pending',
@ivorpad
ivorpad / .sh
Created December 18, 2019 11:18
Posgress
pg_ctl -D /usr/local/var/postgres status
pg_ctl -D /usr/local/var/postgres start
pg_ctl -D /usr/local/var/postgres stop