Skip to content

Instantly share code, notes, and snippets.

View johnbeadle's full-sized avatar

John Beadle johnbeadle

  • Cirencester
View GitHub Profile
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 / 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);
@logivad
logivad / deferred.js
Last active June 2, 2018 13:06
Stupid simple Deferred constuctor
function Deferred() {
this.fulfilled = false;
this.promise = new Promise((resolve, reject) => {
this.interval = setInterval((function() {
if (this.fulfilled && this.resolvedValue !== undefined) {
resolve(this.resolvedValue);
clearInterval(this.interval);
}
if (this.fulfilled && this.errorValue !== undefined) {
reject(this.errorValue);
@atinux
atinux / async-foreach.js
Last active February 2, 2026 23:07
JavaScript: async/await with forEach()
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
await waitFor(50)
@lattner
lattner / async_swift_proposal.md
Last active October 30, 2025 15:46 — forked from oleganza/async_swift_proposal.md
Concrete proposal for async semantics in Swift

Async/Await for Swift

Introduction

Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.

This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.

@davidhund
davidhund / print.css
Created April 14, 2017 08:52
An example (starter) Print stylesheet
/**
* = PRINT styles
*
* - Imported in global.css (http://www.phpied.com/delay-loading-your-print-css/)
* - Taken straight from: https://github.com/h5bp/html5-boilerplate/blob/master/src/css/main.css#L197
*
* @TODO:
* - Add to this?
*
* ========================================================================= */
@arxdsilva
arxdsilva / working_directory.go
Last active January 6, 2025 19:29
How to get the current working directory in golang
package main
// More info on Getwd()
// https://golang.org/src/os/getwd.go
//
import(
"os"
"fmt"
"log"
)
@cmoulton
cmoulton / URLSession Calls in Swift 3.0.1
Last active November 4, 2022 00:29
URLSession Calls in Swift 3.0.1
func makeGetCall() {
// Set up the URL request
let todoEndpoint: String = "https://jsonplaceholder.typicode.com/todos/1"
guard let url = URL(string: todoEndpoint) else {
print("Error: cannot create URL")
return
}
let urlRequest = URLRequest(url: url)
// set up the session
@parmentf
parmentf / GitCommitEmoji.md
Last active March 16, 2026 01:28
Git Commit message Emoji
@blixt
blixt / HexToUIColor.swift
Last active July 28, 2021 05:19
A Swift String extension that converts a hexadecimal color to a UIColor.
import UIKit
extension String {
var hexColor: UIColor? {
let hex = self.stringByTrimmingCharactersInSet(NSCharacterSet.alphanumericCharacterSet().invertedSet)
var int = UInt32()
guard NSScanner(string: hex).scanHexInt(&int) else {
return nil
}
let a, r, g, b: UInt32