Skip to content

Instantly share code, notes, and snippets.

View SauloSilva's full-sized avatar

Saulo Santiago SauloSilva

View GitHub Profile
@SauloSilva
SauloSilva / config_sublime
Created April 8, 2013 12:34
configuration sublime.
{
"auto_complete": true,
"binary_file_patterns":
[
"*.jpg",
"*.jpeg",
"*.png",
"*.gif",
"*.ttf",
"*.tga",
@SauloSilva
SauloSilva / resize.js
Created August 1, 2013 19:14
Resize, element html, pure javascript.
var object = undefined
, minimum = undefined
, count = 0
, limit = 0
, skip = 5
, interval = undefined;
function expand(width) {
object = document.getElementById('super');
minimum = object.offsetWidth;
@SauloSilva
SauloSilva / ms_to_days.js
Last active December 21, 2015 17:38
Transform ms in days, hours, minutes and seconds.
// example 1: format "Days" : days, "Hours" : hours, "Minutes" : minutes, "Seconds" : seconds
millisToTime = function(ms) {
x = ms / 1000;
seconds = Math.round(x % 60);
x /= 60;
minutes = Math.round(x % 60);
x /= 60;
hours = Math.round(x % 24);
x /= 24;
days = Math.round(x);
@SauloSilva
SauloSilva / resize_vm.txt
Created September 17, 2013 19:10
resize_vm
/Applications/VirtualBox.app/Contents/MacOS/VBoxManage modifyhd YOUR_HARD_DISK.vdi –resize SIZE_IN_MB
@SauloSilva
SauloSilva / inset_jquery_on_page.js
Created September 27, 2013 13:02
Inset jquery on page via inspector element.
var jq = document.createElement('script');
jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
jQuery.noConflict();
@SauloSilva
SauloSilva / split.coffee
Created October 2, 2013 04:02
split array in js. Ex: [1,2,3,4,5,6,7] by 2 transform to [[1,2], [3,4], [5,6], [7]]
split = (array, numberOf) ->
matrix = []
indice = 0
aux = -1
while indice < array.length
if indice % numberOf is 0
aux++
matrix[aux] = []
matrix[aux].push array[indice]
@SauloSilva
SauloSilva / scale.js
Created November 12, 2013 16:38
scale element
window.scaler = function(options) {
var a, ab, b, c, cd, d, e, f, scale;
a = options.srcWidth;
b = options.srcHeight;
c = options.windowWidth;
d = options.windowHeight;
console.log(c, d);
ab = a / b;
cd = c / b;
e = 0;
@SauloSilva
SauloSilva / case.sql
Created November 19, 2013 14:53
sql case
SELECT STRAIGHT_JOIN categories.id, categories.title, categories.game_count, categories.display_order FROM `categories` INNER JOIN `category_namespaces` ON `category_namespaces`.`category_id` = `categories`.`id` WHERE `categories`.`type` IN ('ClickJogos::GameCategory') AND `categories`.`published` = 1 AND (category_namespaces.namespace = 'jgo') ORDER BY
CASE
WHEN categories.id LIKE '447%' THEN 1
WHEN categories.id LIKE '448%' THEN 2
ELSE 3
END, categories.game_count DESC;
do (Backbone) ->
method =
cacheOrFetch: (options={}) ->
@_cache ?= @fetch(options)
_.extend(Backbone.Collection.prototype, method)
@SauloSilva
SauloSilva / to_sentence.coffee
Created January 25, 2014 20:36
Clone to setence active support of rails.
Array.prototype.toSentence = ->
wordsConnector = ', '
lastWordConnector = ' e '
sentence = undefined
switch @length
when 0
sentence = ''
when 1
sentence = @[0]