Skip to content

Instantly share code, notes, and snippets.

@cristianobecker
cristianobecker / foca.js
Created September 11, 2014 19:53
Foca no código
/* Foca no código
.---.
/o o\
__(= " =)__
//\'-=-'/\\
) (_
/ `"=-._
/ \ ``"=.
@cristianobecker
cristianobecker / cpf.js
Last active April 26, 2016 17:17
Validar CPF por javascript
var CPF = (function () {
var eleven = 11;
function mod(n) {
var t = eleven,
a = n % t;
return (a < 2 ? 0 : t - n % t) + '';
}
@cristianobecker
cristianobecker / vogal.js
Created September 23, 2014 19:59
Obter somente vogais
var utils = {};
utils.vogal = function (str) {
var h = Object.prototype.hasOwnProperty,
v = (str + '').replace(/[^aeiou]/g, ''),
d = {},
n;
for (var i in v) {
n = v[i];
if (h.call(d, n)) {
@cristianobecker
cristianobecker / time-error.js
Created October 16, 2014 18:36
BRST problem in Javascript Date object
function nextDay() {
var date = new Date(2014, month, now + 1);
now = date.getDate();
return date;
}
var month = 9,
now = 0,
max = 50,
curr;
@cristianobecker
cristianobecker / type.js
Created October 17, 2014 19:24
Get the type of any object in JavaScript
function type(e) {
var t = Object.prototype.toString.call(e),
r = /\[object (\w+)\]/i.exec(t);
return r && r[1].toLowerCase();
}
[1,"2", true, null, [], {}, function() {}, undefined].forEach(function(e){
console.log(type(e))
});
@cristianobecker
cristianobecker / thumb.sh
Created March 6, 2015 17:03
Edit multiple images with imagemagik (resize, optimize and thumbnail)
# RESIZE AND OPTIMIZE (based in height)
HEIGHT=500
mkdir -p result
for f in *.jpg; do
convert "$f" -resize "x${HEIGHT}" -strip -quality 90% "result/$f"
done
# THUMB
WIDTH=200
HEIGHT=225
@cristianobecker
cristianobecker / convert-xbox.sh
Last active January 14, 2016 16:00
Convert a MKV file to MP4 with subtitles (xbox360 compatible) using ffmpeg
xbox-convert() {
if test $# -eq 1; then
local extension=$(echo "$1" | egrep -o '\.[^\.]+$')
local file=$(echo "$1" | sed -e "s/"$extension"$//")
if test -f "$file.srt" && test -f "$1"; then
ffmpeg -sub_charenc "ISO-8859-1" -i "$file.srt" "$file.ass"
ffmpeg -i "$1" -vf ass="$file.ass" -vcodec libx264 -acodec ac3 -ab 160k "$file.mp4"
rm "$file.ass"
else
echo ".str file and video file should have the same name"
@cristianobecker
cristianobecker / my-proxy.sh
Created May 2, 2015 18:12
Use SSH Tunnel as a SOCKS proxy on MacOS
my-proxy() {
sudo networksetup -setsocksfirewallproxystate Wi-Fi on
sudo networksetup -setsocksfirewallproxy Wi-Fi localhost 8001
ssh cbecker -C -N -D 8001 # change your ssh info here
sudo networksetup -setsocksfirewallproxystate Wi-Fi off
}
@cristianobecker
cristianobecker / radio.sh
Last active January 14, 2016 16:00
Internet radio to work
radio() {
local radio
local station
local playlist
if test $# -eq 2; then
radio="$1"
station="$2"
elif test $# -eq 0; then
radio=soma
@cristianobecker
cristianobecker / main.js
Created June 15, 2015 00:42
Main.js file when using jQuery
/*global jQuery */
/*jslint browser: true */
(function (win, $) {
'use strict';
// helpers
var Util, Globals;