Skip to content

Instantly share code, notes, and snippets.

View asaschachar's full-sized avatar

Asa Schachar asaschachar

View GitHub Profile
# myapp.rb
require 'sinatra'
get '/' do
'Hello world!'
end
# optly.rb
require 'singleton'
require 'logger'
require 'optimizely/optimizely_factory'
class Optly
include Singleton
def initialize
sdk_key = '<Your_SDK_Key>'
func handleRequest(c *gin.Context) {
userObj := map[string]string{"userId": "user123"}
jsonString, _ := json.Marshal(userObj)
req, _ := http.NewRequest("POST", "http://localhost:8080/v1/activate", bytes.NewBuffer(jsonString))
q := req.URL.Query()
q.Add("featureKey", "hello_world")
@asaschachar
asaschachar / App.js
Last active May 15, 2020 04:58
ReactABTests
/* Complete code example of App.js by the end of the video */
/* NOTE: Replace <Your_SDK_Key> with the SDK Key of your project below */
import React from 'react';
import logo from './logo.svg';
import './App.css';
import {
createInstance,
OptimizelyFeature,
OptimizelyProvider,
withOptimizely

React Feature Flags

Set up your environment

  1. Open a Terminal window.
  2. Install Homebrew. Be sure to press Enter and put in your computer password when asked.
  3. Install Node by running the following in the terminal: brew install node
  4. Install Yarn by running the following in the terminal: brew install yarn
  5. Install Visual Studio Code as your text editor (instead of vi)
  6. Congrats! Your computer is now setup for coding in React. 💻
  7. Navigate to the Optimizely docs and follow along the video with the next set of instructions

HTTP Proxy

Our SDK uses the standard node http(s) request library, which unfortunately does not automatically pull in environment-defined proxy settings. I think the current options are:

Option 1: Use a Node package for Proxying

Use global-agent to set the proxy settings for the http library so that requests from http use your proxy.

  1. npm install --save global-agent
  2. Before you use the Optimizely SDK:
@asaschachar
asaschachar / App.js
Created September 11, 2019 17:15
Capture The Flag - Complete Example
import React from 'react';
import logo from './logo.svg';
import './App.css';
import {
createInstance,
OptimizelyProvider,
OptimizelyFeature,
} from '@optimizely/react-sdk'
import React from 'react';
import {
createInstance,
OptimizelyProvider,
} from '@optimizely/react-sdk'
const optimizely = createInstance({
sdkKey: '<Your_SDK_Key>',
})
import React from 'react';
import {
createInstance,
OptimizelyProvider,
OptimizelyFeature,
} from '@optimizely/react-sdk'
const optimizely = createInstance({
sdkKey: '<Your_SDK_Key>',
})
import React, {Fragment} from 'react';
import { StyleSheet, View, Text } from 'react-native';
import {
createInstance,
OptimizelyProvider,
OptimizelyFeature,
enums,
setLogger,
} from '@optimizely/react-sdk'