Skip to content

Instantly share code, notes, and snippets.

View remotesynth's full-sized avatar

Brian Rinaldi remotesynth

View GitHub Profile
@remotesynth
remotesynth / index.js
Created November 7, 2022 21:19
Deno Deploy function calling the LaunchDarkly API for flag values
import { serve } from "https://deno.land/std@0.114.0/http/server.ts";
import { DOMParser } from "https://esm.sh/linkedom";
async function handler(req: Request): Promise<Response> {
const document = new DOMParser().parseFromString(`<html>
<head><title>Just a simple page</title></head>
<body>
<h1>This header will change</h1>
<p>The above header will change depending on the flag value.</p>
</body>
@remotesynth
remotesynth / index.js
Last active June 6, 2023 13:15
Cloudflare Worker with LaunchDarkly integration
import { getAssetFromKV } from "@cloudflare/kv-asset-handler";
const { init } = require("launchdarkly-cloudflare-edge-sdk");
let ldClient;
class FlagsStateInjector {
async element(element) {
// fetch all flag values for client-side SDKs as evaluated for an anonymous user
// use a more appropriate user key if needed
const user = {
key: "anonymous",
@remotesynth
remotesynth / _app.ts
Created February 2, 2022 19:59
Next.js _app.ts with LaunchDarkly
import { AppProps } from 'next/app'
import '../styles/index.css'
import { withLDProvider } from "launchdarkly-react-client-sdk";
function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
export default withLDProvider({
clientSideID: process.env.LAUNCHDARKLY_SDK_CLIENT!,
@remotesynth
remotesynth / _app.js
Created February 2, 2022 19:58
Next.js _app.js with LaunchDarkly
import { AppProps } from 'next/app'
import '../styles/index.css'
function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
export default withLDProvider({
clientSideID: process.env.LAUNCHDARKLY_SDK_CLIENT,
})(MyApp);
@remotesynth
remotesynth / _app.js
Created February 2, 2022 19:57
Next.js _app.js
import { AppProps } from 'next/app'
import '../styles/index.css'
export default function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
@remotesynth
remotesynth / index.ts
Last active February 2, 2022 19:59
LaunchDarkly in Node.js with TypeScript
import * as LaunchDarkly from "launchdarkly-node-server-sdk";
import * as dotenv from "dotenv";
dotenv.config({ path: __dirname + "/.env" });
let ldClient: LaunchDarkly.LDClient;
async function getClient(): Promise<LaunchDarkly.LDClient> {
const client = LaunchDarkly.init(process.env.LAUNCHDARKLY_SDK_KEY);
await client.waitForInitialization();
return client;
@remotesynth
remotesynth / app.js
Last active December 5, 2015 15:29
Parsing locations James Bond has been
var request = require("request"),
cheerio = require("cheerio"),
ProgressBar = require('progress'),
Knwl = require("knwl.js"),
apiURL = "http://jamesbond.wikia.com/api/v1/Articles/List?category=James_Bond_films&limit=50",
baseURL = "http://jamesbond.wikia.com";
console.log("Target: James Bond");
// get the full list of movies from the API
request(apiURL, function (error, response, body) {