Skip to content

Instantly share code, notes, and snippets.

View Gabri3l's full-sized avatar

Gabriele Cimato Gabri3l

View GitHub Profile
async function handleRetry(
functionToRetry,
functionName,
operationId,
previousAttemptNumber,
...args
) {
try {
return functionToRetry(...args);
} catch (err) {
func BytesArrayToString(data []bytes) string {
bodyBytes, perr := ioutil.ReadAll(data)
if perr != nil {
fmt.Print("UH OH")
}
bodyString := string(bodyBytes)
return bodyString
}
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()
@Gabri3l
Gabri3l / python_batch.py
Created April 11, 2019 22:02 — forked from daidokoro/python_batch.py
Beam Stuff
'''
Apache Beam Python Batch Example
'''
class Batch(beam.DoFn):
"""
Batch - batch items from PCollection
"""
def __init__(self, n):
import json
export const addToFavorites = (item) => ({
type: types.ADD_TO_FAVORITES,
item,
});
export const removeFromFavorites = (itemIndex) => ({
type: types.REMOVE_FROM_FAVORITES,
itemIndex,
});
@Gabri3l
Gabri3l / ReactCanvasDrawing.js
Created September 20, 2016 17:37 — forked from sebmarkbage/ReactCanvasDrawing.js
Canvas Drawing Example
/** @jsx React.DOM */
var Graphic = React.createClass({
componentDidMount: function() {
var context = this.getDOMNode().getContext('2d');
this.paint(context);
},
componentDidUpdate: function() {
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();
/*
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;
}
/*
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
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);