Skip to content

Instantly share code, notes, and snippets.

View yakkomajuri's full-sized avatar

Yakko Majuri yakkomajuri

View GitHub Profile
// babel.config.js
module.exports = {
presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'],
}
import React from 'react'
export const MyJSComponent = () => (
<h2>Try out the counter below!</h2>
)
import React from 'react'
import { hot } from 'react-hot-loader/root'
import { MyJSComponent } from './components/MyJSComponent'
import { Counter } from './components/Counter'
export const App = hot(_App)
export function _App(): JSX.Element | null {
return (
<div>
<h1>Hello world!</h1>
import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import { getContext, resetContext } from 'kea'
import { App } from './App'
resetContext({
createStore: {},
plugins: [],
})
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>React from Scratch</title>
</head>
<body>
<div id="root"></div>
<noscript> You need to enable JavaScript to access this website. </noscript>
{"uuid":"c284b820-38a1-11eb-a9ed-c36d0805c832","page":{"id":16370859,"data":{"appState":"[\"~#iR\",[\"^ \",\"n\",\"appTemplate\",\"v\",[\"^ \",\"isFetching\",false,\"plugins\",[\"~#iOM\",[\"query1\",[\"^0\",[\"^ \",\"n\",\"pluginTemplate\",\"v\",[\"^ \",\"id\",\"query1\",\"type\",\"datasource\",\"subtype\",\"SqlQueryUnified\",\"namespace\",null,\"resourceName\",\"PH Playground DB\",\"template\",[\"^3\",[\"queryRefreshTime\",\"\",\"records\",\"\",\"databasePasswordOverride\",\"\",\"queryDisabledMessage\",\"\",\"successMessage\",\"\",\"queryDisabled\",\"\",\"playgroundQuerySaveId\",0,\"resourceNameOverride\",\"\",\"runWhenModelUpdates\",true,\"query\",\"select * from posthog_event;\",\"playgroundQueryUuid\",\"\",\"playgroundQueryId\",0,\"privateParams\",[\"~#iL\",[]],\"triggersOnSuccess\",[\"^9\",[]],\"runWhenPageLoadsDelay\",\"\",\"warningCodes\",[\"^9\",[]],\"data\",null,\"recordId\",\"\",\"importedQueryInputs\",[\"^3\",[]],\"showSuccessConfetti\",false,\"isImported\",false,\"showSuccessToaster\",true,\"dataA
@yakkomajuri
yakkomajuri / feature-flags.js
Created September 30, 2020 14:29
PostHog Feature Flags Playground
const resultElementFlag1 = document.getElementById('result-flag-1')
const resultElementFlag2 = document.getElementById('result-flag-2')
const iceCreamSelectorElement = document.getElementById('select-ice-cream')
const savePreferenceElement = document.getElementById('save-preference-btn')
const loadingRingElement = document.getElementById('loading-ring')
let loadingRingOn = false
posthog.init('sTMFPsFhdP1Ssg', { api_host: 'https://app.posthog.com', loaded: () => { updateFeatureFlagsDisplay(0) } })
const updateFeatureFlagsDisplay = (timeout) => {
# Property filtering logic omitted
# Rollout percentage logic:
__LONG_SCALE__ = float(0xFFFFFFFFFFFFFFF)
def _hash(self, key: str, distinct_id: str) -> float:
hash_key = "%s.%s" % (key, distinct_id)
hash_val = int(hashlib.sha1(hash_key.encode("utf-8")).hexdigest()[:15], 16)
return hash_val / __LONG_SCALE__
proc sum(arr: openArray[int]): int =
for num in arr:
result += num
proc double[T](x: T): T {.inline, noSideEffects.} =
2 * x