Skip to content

Instantly share code, notes, and snippets.

View williammustaffa's full-sized avatar
🎯

William Lima williammustaffa

🎯
View GitHub Profile
@williammustaffa
williammustaffa / customToFixed.js
Last active July 17, 2018 19:00
custom toFixed to prevent rounding values
Number.prototype.customToFixed = function (digits) {
return parseFloat(String(this).replace(new RegExp(`(\\d+\\.\\d{${digits}}).*`), '$1'));
};
/**
* "string".cuckalize(value)
* transform any word into a custom object
*
* @param {Any} v Variable value
*
* @return {Object}
*/
String.prototype.cuckalize = function (v) { return this.split('').reverse().reduce((p, c) => ({ [c]: p }), v) };
@ruudud
ruudud / example.ftl
Created January 18, 2016 13:59
Freemarker JSON dump
<#assign foo><@objectToJson object=data.myobj /></#assign>
${foo?html}
<#macro objectToJson object>
<@compress single_line=true>
<#if object?is_hash || object?is_hash_ex>
<#assign first="true">
{
<#list object?keys as key>
<#if first="false">,</#if>
@williammustaffa
williammustaffa / CANVAS RETROFFECT
Last active August 29, 2015 14:15
Effects: RGB shift, Scan Lines, TV Shine, TV noise
/*
* SCRIPT BY WILLIAM LIMA
* NAME: CANVAS RETROFFECT
* DATE: 08/02/2015
* LANGUAGE: JAVASCRIPT
* USAGE: draw_rgb_shift(CanvasElement,EnableRgbShift,EnableScanLine,EnableShine,EnableTvNoise)
* USE THE FUNCTION INTO ### AN ANIMATION FRAME ### BUT CREATE IT OUTSIDE
*/
var room={height: canvas.height,width: canvas.width,currentTime:0}
function draw_rgb_shift(canvas,rgbshift,scanline,shine,noise){
@mallendeo
mallendeo / start-end-week.js
Created February 9, 2014 18:22
Get start and end of week with Momentjs
// include jquery, momentjs
$(function () {
var m = moment();
m.lang('es'); // week start on monday
var start = m.startOf('week').format('DD'),
end = m.endOf('week').format('DD'),
month = m.endOf('week').format('MMMM'),
afterMonth = start > end ? ' de '+m.startOf('week').format('MMMM') : '',