Skip to content

Instantly share code, notes, and snippets.

@jesusgoku
jesusgoku / canonicalize.php
Created March 1, 2016 18:39
Canonicalize string for compare on PHP
<?php
$file = 'hola.jpg';
echo substr($file, strrpos($file, '.'));
function canonicalize($input)
{
return strtolower(preg_replace('/[^\w -]/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $input)));
}
@jesusgoku
jesusgoku / copy_with_progress.sh
Created March 25, 2016 17:01
Copy files with progress
rsync -ah --progress source-file destination
@jesusgoku
jesusgoku / jwt_hs256.sh
Last active August 22, 2017 16:32
JWT HS256
#!/bin/bash
function jwt_hs256 {
SECRET="$1"
DATA="$2"
HEADER=`echo -n '{"alg":"HS256","typ":"JWT"}' | base64`
PAYLOAD=`echo -n $DATA | base64`
UNSIGNED_TOKEN="${HEADER}.${PAYLOAD}"
SIGNATURE=`echo -n "${UNSIGNED_TOKEN}" | openssl dgst -sha256 -hmac "${SECRET}" -binary | base64 | sed -e 's/=//g' | sed -e 's/+/-/g' | sed -e 's/\//_/g'`
echo "${HEADER}.${PAYLOAD}.${SIGNATURE}"
@jesusgoku
jesusgoku / .editorconfig
Created June 23, 2016 21:07 — forked from ankr/.editorconfig
Base editorconfig for new projects
# Base editorconfig for new projects
root = true
[*]
end_of_line = lf
indent_style = space
tab_width = 4
charset = utf-8
trim_trailing_whitespace = true
@jesusgoku
jesusgoku / draggable-element.js
Created October 19, 2016 16:13
Draggable element on parent container (example: body)
;(function (global) {
var DraggableElement = function (parent, el) {
el.setAttribute('draggable', true);
el.addEventListener('dragstart', onDragStart, false);
parent.addEventListener('dragover', onDragOver, false);
parent.addEventListener('drop', onDropFactory(el), false);
};
function onDragStart(e) {
var style = global.getComputedStyle(e.target, null);
@jesusgoku
jesusgoku / cookies.js
Created December 20, 2016 16:15
JavaScript cookies utility
;(function (window, document) {
function Cookies() {}
(function () {
var self = this;
self._get_cookies = function () {
var cookies = {};
document
@jesusgoku
jesusgoku / track-all-remote-branch.sh
Created January 12, 2017 18:07
GIT: Track all remote branch
#!/bin/bash
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do
git branch --track ${branch#remotes/origin/} $branch
done
@jesusgoku
jesusgoku / helper_utils.py
Created February 8, 2017 18:54
Django templatetags filter for dump of a variable
from django import template
from django.template.defaultfilters import linebreaksbr
from django.utils.html import escape
try:
from django.utils.safestring import mark_safe
except ImportError: # v0.96 and 0.97-pre-autoescaping compat
def mark_safe(x): return x
from pprint import pformat
def rawdump(x):
@jesusgoku
jesusgoku / parallel_concurrent.py
Created April 20, 2017 15:39
Testing difference execute code on Serial, Threads, Processes
#!/usr/bin/env python
from __future__ import print_function, generators
import os
import time
import threading
import multiprocessing
@jesusgoku
jesusgoku / postactivate
Created June 21, 2017 16:01
virtualenvwrapper ... hooks for create folder post create virtualenv and cd to folder post activate virtualenv
#!/usr/local/bin sh
# This hook is sourced after every virtualenv is activated.
# PROJECT_HOME is defined in your envrironment with folder for save your projects
# example (add to your .bashrc or .zshrc):
# export PROJECT_HOME="${HOME}/Projects"
PROJECT_NAME=$(basename "$VIRTUAL_ENV")
cd "${PROJECT_HOME}/${PROJECT_NAME}"