This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function handleRetry( | |
functionToRetry, | |
functionName, | |
operationId, | |
previousAttemptNumber, | |
...args | |
) { | |
try { | |
return functionToRetry(...args); | |
} catch (err) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func BytesArrayToString(data []bytes) string { | |
bodyBytes, perr := ioutil.ReadAll(data) | |
if perr != nil { | |
fmt.Print("UH OH") | |
} | |
bodyString := string(bodyBytes) | |
return bodyString | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tempfile | |
import json | |
from google.cloud import storage | |
def upload_from_temp_file(some_data): | |
with tempfile.NamedTemporaryFile() as fp: | |
json_data = json.dumps(some_data) | |
fp.write(json_data.encode()) | |
fp.flush() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Apache Beam Python Batch Example | |
''' | |
class Batch(beam.DoFn): | |
""" | |
Batch - batch items from PCollection | |
""" | |
def __init__(self, n): | |
import json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const addToFavorites = (item) => ({ | |
type: types.ADD_TO_FAVORITES, | |
item, | |
}); | |
export const removeFromFavorites = (itemIndex) => ({ | |
type: types.REMOVE_FROM_FAVORITES, | |
itemIndex, | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @jsx React.DOM */ | |
var Graphic = React.createClass({ | |
componentDidMount: function() { | |
var context = this.getDOMNode().getContext('2d'); | |
this.paint(context); | |
}, | |
componentDidUpdate: function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var imageQuality = 0.7; | |
var scale = 0.35; | |
$container = $('#resize' + id + 'Container'); | |
var crop_canvas, | |
left = $('#pic' + id + 'Overlay').offset().left - $container.offset().left, | |
top = $('#pic' + id + 'Overlay').offset().top - $container.offset().top, | |
width = $('#pic' + id + 'Overlay').width(), | |
height = $('#pic' + id + 'Overlay').height(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Return the last digit of str1 to the power of str2. They can potentially be two very big values. | |
*/ | |
function lastDigit(str1, str2){ | |
if (+str2 === 0) return 1; | |
if (+str1.slice(-1) === 0 && str1.length > 1) return 0; | |
return Math.pow(+str1.slice(-1), +str2.slice(-2)%4 || 4) % 10; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Description: | |
Implement a function solve_graph(start, end, arcs) that will return true if the end node can be reached from the start node, | |
using 0 or more arcs. It will return false if it is not possible. | |
The graph is defined by a list of arcs, where each arc is an object that has two properties, start and end, representing the | |
start and end nodes, respectively. Each arc is unidirectional, in other words it goes from a start node to an end node, and | |
not the other way around. Note that 0 or more arcs can leave a node, and 0 or more can arrive to it. | |
Note that the solve_graph() method doesn't take a list of nodes as input: for simplicity's sake, let's assume that all nodes | |
present in arcs are valid. However, the start or end node may not be in arcs. | |
An example |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Event() { | |
let subscribers = []; | |
const subscribe = (...values) => { | |
values.forEach((s) => { | |
if (typeof s === 'function') subscribers.push(s); | |
}); | |
}; | |
const unsubscribe = (...values) => { | |
values.forEach((v) => { | |
if (subscribers.lastIndexOf(v) > -1) subscribers.splice(subscribers.lastIndexOf(v),1); |
NewerOlder