Skip to content

Instantly share code, notes, and snippets.

View Gabri3l's full-sized avatar

Gabriele Cimato Gabri3l

View GitHub Profile
/*
This gist is to show a differnet approach on the merging task. Some
conditions might be missing but I just wanted to present a different
implementation, adding or editing a constraint is pretty straighforward.
*/
'use strict';
const constraint = (passingCondition, consequence) => ({
passed: passingCondition,
applyConsequence: consequence
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);
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) => {
/*
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
/*
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;
}
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();
@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() {
export const addToFavorites = (item) => ({
type: types.ADD_TO_FAVORITES,
item,
});
export const removeFromFavorites = (itemIndex) => ({
type: types.REMOVE_FROM_FAVORITES,
itemIndex,
});
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++) {
@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