Skip to content

Instantly share code, notes, and snippets.

View insign's full-sized avatar
🇧🇷
being open-sourcerer

Hélio insign

🇧🇷
being open-sourcerer
View GitHub Profile
@insign
insign / aggregate.js
Created January 11, 2018 22:50
Faster alternative for Array.reduce()
Array.prototype.aggregate = function (fn, initialValue) {
let current
const length = this.length
if (length == 0 && initialValue) return initialValue
else if (length == 0) throw 'Reduce of empty array with no initial value'
else if (length == 1 && initialValue) return fn(initialValue, this[0])
else if (length == 1) return this[0]
else if (initialValue) current = fn(initialValue, this[0])
else current = this[0]
@insign
insign / all.js
Created June 7, 2017 16:47
Teste de promisses
let os = require('os')
let nativefier = require('nativefier').default
let c = require('colors')
let icon = './src/icon.png'
let options = {
name: 'Gmail Desktop',
targetUrl: 'https://mail.google.com/mail/mu/?mui=ca',
<template>
<!-- root node required -->
<div>
<grid-layout :layout="layout" :col-num="12" :row-height="30" :is-draggable="true" :is-resizable="true" :vertical-compact="true" :margin="[10,10]" :use-css-transforms="true">
<grid-item v-for="item in layout" :x="item.x" :y="item.y" :w="item.w" :h="item.h" :i="item.i">
{{content[item.i].text}}
</grid-item>
</grid-layout>
</div>
</template>
<?php
public function store()
{
$product = $this->createProduct();
$this->applyDiscount('newProduct', $product);
$this->notifyUsersVia('email');
return 'Success';
}
<?php
public function store()
{
$product = $this->createProduct();
$this->applyDiscount('newProduct', $product);
$this->notifyUsersVia('email');
return 'Success';
}
<?php
// This will create a product, apply a discount since it is a new
// product, and send a notification via email
public function store()
{
// Create product from request
$product = Product::create($request->all());
// Get the discount to be applied
$discount = Discount::byType('newProduct');
<?php
protected function createProduct()
{
return Product::create($this->request->all());
}
protected function applyDiscount($type, $product)
{
$discount = Discount::byType($type);
<?php
protected function createProduct()
{
}
protected function applyDiscount($type, $product)
{
}
<?php
// This will create a product, apply a discount since it is a new
// product, and send a notification via email
public function store()
{
// Create product from request
$product = Product::create($request->all());
// Get the discount to be applied
$discount = Discount::byType('newProduct');
@insign
insign / calcular.php
Created October 8, 2013 03:48
Cálculo de Prescrição (simulação)
<?php
require_once 'cdp.class.php';
$cdp = new CalculoDePrescricao;
$cdp->data_do_crime = $_POST['data_do_crime'];
$cdp->data_da_denuncia = $_POST['data_da_denuncia'];
$cdp->idade_criminoso = $_POST['idade_criminoso'];
$cdp->pena_maxima = $_POST['pena_maxima'];