Skip to content

Instantly share code, notes, and snippets.

View johnbeadle's full-sized avatar

John Beadle johnbeadle

  • Cirencester
View GitHub Profile
@johnbeadle
johnbeadle / chan_multiplexing.go
Created July 11, 2019 23:09
How to use fanIn type function to allow non-blocking use of channel
package main
import (
"fmt"
"math/rand"
"time"
)
func boring(msg string) <-chan string {
c := make(chan string)
if(lpTag && lpTag.events && lpTag.events.bind) {
lpTag.events.bind('lpUnifiedWindow','conversationInfo', (data,eventInfo) => {
// push to GTM once event is interactive.
if ( data.state && data.state == 'interactive') {
dataLayer.push(
{
});
import React, { Component } from "react";
import logo from "./logo.svg";
import "./App.css";
const Child = ({ onClick }) => <button onClick={onClick}>Click me</button>;
class Parent extends Component {
field = "hello";
handleClick = e => {
@johnbeadle
johnbeadle / idle_time_in_conversation.swift
Created January 31, 2018 19:41
how to create a timer on connection changed = true to monitor idle time
var idleTimer:Timer? // a timer
var refreshTokenInProgress:Bool = false // a bool to track if you are already in the process of refreshing a token when the timer ticks over again
// function registered in your delegate handler class for monitoring connnection state changed from the SDK
func LPMessagingSDKConnectionStateChanged(_ isReady: Bool, brandID: String) {
// isReady = true = connected on conversation screen = then start your timer
if(isReady) {
print("@@@ connection state changed to \(isReady)")
if( idleTimer?.isValid == false) {
runTimer()
@johnbeadle
johnbeadle / tag_manager_example.html
Created January 5, 2018 21:15
all-in-one tag manager example
<script type="text/javascript">
window.lpTag = window.lpTag || {}; // REQUIRED to ensure lpTag {} exists prior to SDE push
window.lpTag.autoStart = false; // disable AUTOSTART
window.lpTag.site = "90233546"; // replace with your desired account number
window.lpTag=window.lpTag||{},"undefined"==typeof window.lpTag._tagCount?(window.lpTag={site:lpTag.site||"90233546",section:lpTag.section||"",tagletSection:lpTag.tagletSection||null,autoStart:lpTag.autoStart!==!1,ovr:lpTag.ovr||{},_v:"1.7.0",_tagCount:1,protocol:"https:",events:{bind:function(t,e,i){lpTag.defer(function(){lpTag.events.bind(t,e,i)},0)},trigger:function(t,e,i){lpTag.defer(function(){lpTag.events.trigger(t,e,i)},1)}},defer:function(t,e){0==e?(this._defB=this._defB||[],this._defB.push(t)):1==e?(this._defT=this._defT||[],this._defT.push(t)):(this._defL=this._defL||[],this._defL.push(t))},load:function(t,e,i){var n=this;setTimeout(function(){n._load(t,e,i)},0)},_load:function(t,e,i){var n=t;t||(n=this.protocol+"//"+(this.ovr&&this.ovr.domain?this.o
@johnbeadle
johnbeadle / voice_to_cobrowse_sample.html
Last active January 23, 2018 16:20
how to start a voice to CoBrowse session
<!--
PLEASE NOTE:
This sameple DOES NOT include the standard liveperson tag which should already be included on all pages you wish to start,
continue cobrowse live sharing on
-->
<a href="#" onclick="enterServiceNumber();">Live Share</a>
<script type='text/javascript'>
function requestCobrowse(serviceId) {
console.log('requestCoBrowse function ... ',serviceId);
@johnbeadle
johnbeadle / destroy_and_close_chat_in_progress.js
Last active September 4, 2017 11:27
how to detect a chat is in progress and take action
/*
*************** PLEASE NOTE *************
* This code is POC -- should be TESTED BEFORE BEING ADDED TO PRODUCTION WEBSITE
* Assumes will only be added to specific pages (logout) where you want this behaviour
* Assumes the page is already tagged with liveperson general code and account number
*/
var LP_CHAT_WINDOW_PARENT_ELEMENT_ID = "lpChat";
if (this.postData != null) {
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
Iterator<?> keys = postData.keys(); // get the object keys
// loop through them
while( keys.hasNext() ) {
String key = (String)keys.next(); //get the postData key
if ( postData.get(key) instanceof JSONObject ) {
// do something else
} else if( postData.get(key) instanceof String) {
writer.write(key+"="+postData.get(key)+"&");
@johnbeadle
johnbeadle / JSONTask.java
Created August 24, 2017 16:33
Creating AsyncTask
private class JSONTask extends AsyncTask<String,String, String > {
// This is the JSON body of the post
JSONObject postData;
// This is a constructor that allows you to pass in the JSON body
public JSONTask(Map<String, String> postData) {
if (postData != null) {
this.postData = new JSONObject(postData);
}
}
@johnbeadle
johnbeadle / params.java
Last active August 24, 2017 16:42
setting params as HashMap
Map<String, String> postData = new HashMap<>();
postData.put("sub", user.sub);
postData.put("exp", user.tokenExpirationInMinutes);
postData.put("fname", user.firstname);
postData.put("lname", user.lastname);
postData.put("email", user.email);
new JSONTask(postData).execute("/api/token/");