Skip to content

Instantly share code, notes, and snippets.

@tore-statsig
tore-statsig / bunnylol.ts
Created August 31, 2022 20:06
bunnylol example
import type { NextApiRequest, NextApiResponse } from "next";
import Statsig from "statsig-node";
import { getSession } from "next-auth/react";
enum Command {
chat,
g,
gh,
google,
@tore-statsig
tore-statsig / app_and_service_worker.js
Created August 18, 2022 18:20
Using statsig-js client sdk in a service worker
// app.js
const messageChannel = new MessageChannel();
function setup() {
navigator.serviceWorker.controller.postMessage({
type: 'INIT_PORT',
}, [messageChannel.port2]);
messageChannel.port1.onmessage = (event) => {
console.log(event.data);
@tore-statsig
tore-statsig / gcp_function.js
Last active April 22, 2022 18:14
gcp cloud function using statsig-node server sdk
const statsig = require('statsig-node');
let requestsHandled = 0;
const initStart = Date.now();
let initEnd = 0;
let initialized = false;
const initializationPromise = statsig.initialize(process.env.sdkKey).then(() => {
initEnd = Date.now();
initialized = true;
});
@tore-statsig
tore-statsig / gist:015a2a1477bdb68c7b9db43476d7bfa5
Last active March 22, 2022 18:57
React SDK get stable id
import logo from './logo.svg';
import './App.css';
import {StatsigProvider, Statsig, useConfig, useGate, useExperiment, StatsigContext} from 'statsig-react';
import {useEffect, useState, useContext} from 'react';
function Component({updateUser}) {
const config = useConfig('test_config');
const gate = useGate('always_on_gate').value;
console.log(gate);
console.log(config);
@tore-statsig
tore-statsig / StatsigManuallyInitializedProvider.tsx
Created March 1, 2022 21:15
StatsigManuallyInitializedProvider.tsx
import React from 'react';
import StatsigContext from './StatsigContext';
import Statsig from './Statsig';
type Props = {
children: React.ReactNode | React.ReactNode[];
userVersion: number;
};
export default function StatsigManuallyInitializedProvider({
@tore-statsig
tore-statsig / statsig.php
Last active November 30, 2021 01:13
statsig.php - a simple php wrapper around the http api
<?php
// Usage
// $user = (object)[];
// $user->userID = 3;
// checkGate($user, "gate_name");
// getConfig($user, "config_name"));
// getExperiment($user, "product_logo_icon_shapes");
@tore-statsig
tore-statsig / gist:9232938ebab7a12f4b46c291fe309801
Created November 3, 2021 21:54
statsig-react 1.0.0 mocking
let mockGates: Record<string, boolean> = {};
jest.mock('statsig-react', () => {
return {
useGate: (gateName: string) => {
return {
isLoading: false,
value: mockGates[gateName] ?? false,
};
},
useConfig: () => {
from ctypes import *
lib = cdll.LoadLibrary("./statsigshared.so")
class GoString(Structure):
_fields_ = [("p", c_char_p), ("n", c_longlong)]
lib.Initialize.argtypes = [GoString]
key = GoString(b"secret-XXXXXXXXXXXXXXXXXXXXXXXXXXX", 34)
@tore-statsig
tore-statsig / statsig_shared.go
Created August 12, 2021 22:23
statsig go c-style shared lib
package main
import "C"
import (
statsig "github.com/statsig-io/go-sdk"
"github.com/statsig-io/go-sdk/types"
)
//export Initialize
@tore-statsig
tore-statsig / search_ranking_v2.ts
Last active July 14, 2021 23:04
search_ranking_v2.ts
if (Statsig.checkGate("search_ranking_v2") {
// use new ranking feature
} else {
// default/fallback to existing experience
}