Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Gabriele Cimato Gabri3l

🎯
Focusing
Block or report user

Report or block Gabri3l

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View upload_from_temp_file.py
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()
View python_batch.py
'''
Apache Beam Python Batch Example
'''
class Batch(beam.DoFn):
"""
Batch - batch items from PCollection
"""
def __init__(self, n):
import json
View FavoritesActions.js
export const addToFavorites = (item) => ({
type: types.ADD_TO_FAVORITES,
item,
});
export const removeFromFavorites = (itemIndex) => ({
type: types.REMOVE_FROM_FAVORITES,
itemIndex,
});
View ReactCanvasDrawing.js
/** @jsx React.DOM */
var Graphic = React.createClass({
componentDidMount: function() {
var context = this.getDOMNode().getContext('2d');
this.paint(context);
},
componentDidUpdate: function() {
View crop-image.js
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();
View last_digit.js
/*
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;
}
View solve_graph.js
/*
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
View advanced-events.js
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);
View spiralize.js
var spiralize = function(size) {
let spiral = [];
for(let i=0;i<size;i++) {
spiral[i] = Array(size).fill(0);
}
let min = 0;
let max = size;
while (min < max ) {
for(let i=min;i<max;i++) {
View first-n-prime-numbers.js
function Primes(){
let primeNumbers = [2];
const first = (n) => {
if (primeNumbers.length >= n) return primeNumbers.slice(0, n + 1);
let value = primeNumbers[primeNumbers.length - 1] + 1;
let isPrime;
while (primeNumbers.length < n) {
isPrime = true;
primeNumbers.some((prime) => {
You can’t perform that action at this time.