Skip to content

Instantly share code, notes, and snippets.

View edorivai's full-sized avatar

Edo Rivai edorivai

View GitHub Profile
async function() {
try {
const someValue = await getSomeValue();
doSomethingWith(someValue);
} catch (error) {
console.error(error);
}
}
async function() {
@edorivai
edorivai / generateAdyenSignature.js
Last active March 22, 2023 20:36
Generates the HMAC signature as required by the Adyen API.
import crypto from 'crypto';
// Docs: https://docs.adyen.com/developers/payments/accepting-payments/hmac-signature-calculation
export default function generateSignature(body, hmacKey) {
const keys = Object
.keys(body)
// Step 1: Sort by keys
.sort();
const values = keys
function reducer(state, action) {
switch (action.type) {
case UPDATE_VOTES:
const updateVotesList = state.polls.map((poll, ind) => {
if (ind === action.question) {
return poll.answers.map((ans, index) =>
index === action.index
? { ...ans, votes: ans.votes + action.votes }
: ans;
);
@edorivai
edorivai / zaida.py
Last active February 28, 2019 12:12
correct = [0, 0, 0];
incorrect = [0, 0, 0];
for i in range(10000):
(correct if train_data.correct[i] == 1 else incorrect)[train_data.group_name[i]].append(1);
plt.hist(correct[0], color='blue', label='correct_0')
...etc
@edorivai
edorivai / machine.js
Created October 15, 2019 13:51
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@edorivai
edorivai / ProductList.tsx
Created March 18, 2020 09:56
Example of vendure react integration with graphql-codegen hooks
import React from "react";
import { notify } from '@vendure/ui-devkit';
import { gql } from 'graphql-tools';
import { useGetProductsLazyQuery, useToggleEnabledMutation } from './generated-by-codegen';
// These queries get detected and processed by graphql-codegen
const GET_PRODUCTS = gql`
query GetProducts($skip: Int, $take: Int) {
products(options: { skip: $skip, take: $take }) {
items { id, name, enabled },
@edorivai
edorivai / machine.js
Last active June 26, 2020 08:18
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@edorivai
edorivai / machine.js
Last active October 1, 2020 11:11
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@edorivai
edorivai / machine.js
Created February 17, 2021 15:46
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@edorivai
edorivai / machine.js
Last active February 23, 2021 12:20
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions