Skip to content

Instantly share code, notes, and snippets.

View hallison's full-sized avatar
😊
I may be slow to respond.

Hallison Batista hallison

😊
I may be slow to respond.
View GitHub Profile
@hallison
hallison / gist:9dc0ecdec3190de9a115405f85ba654c
Created July 25, 2020 00:28
Copy and paste with footer information (from https://braziljournal.com/)
$(document).ready(function() {
$(document).on('copy', function () {
var selection = window.getSelection();
var copyFooter = '<br><br>Leia mais em <a href="' + document.location.href + '">' + document.location.href + '</a>';
var copyHolder = $('<div>', {
html: (selection + '').substring(0, 140) + '...' + copyFooter,
style: {
position: 'absolute',
left: '-99999px'}
}
@hallison
hallison / sites.conf
Last active February 6, 2020 20:17
Deploys para vários sites usando o nome de domínio no nome do diretório
# From https://httpd.apache.org/docs/2.4/mod/mod_authz_core.html
# and https://httpd.apache.org/docs/2.4/vhosts/mass.html.
UseCanonicalName Off
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
<Directory "/home/deploy/sites">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
@hallison
hallison / Decode JWT
Last active December 16, 2019 18:40
JS - Parse JWT
function jwtDecode(token) {
var base64Url = token.split('.')[1];
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
var payload = decodeURIComponent(atob(base64).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
return JSON.parse(payload);
};
@hallison
hallison / array-order-items.js
Last active February 25, 2019 20:47
Order list items in Array
Array.prototype.orderItems = function(newer, older) {
var list = new Array(...this)
return list.splice(newer - 1, 0, ...list.splice(older, 1))
}
@hallison
hallison / SparkLearn.java
Created June 6, 2011 19:44
Howto use a simple renderer for Spark-Java
package learn;
import static spark.Spark.*;
import spark.*;
import java.io.*;
import java.util.Map;
import java.util.HashMap;
import java.util.regex.Pattern;
@hallison
hallison / optparse-template.rb
Created December 1, 2016 17:11 — forked from rtomayko/optparse-template.rb
Ruby optparse template
#!/usr/bin/env ruby
#/ Usage: <progname> [options]...
#/ How does this script make my life easier?
# ** Tip: use #/ lines to define the --help usage message.
$stderr.sync = true
require 'optparse'
# default options
flag = false
option = "default value"
@hallison
hallison / chat.rb
Created January 2, 2012 19:32 — forked from rkh/chat.rb
Simple Chat Application using the Sinatra Streaming API
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
@hallison
hallison / Makefile
Created June 27, 2011 12:51
Vim-Markdown Makefile
# Configuration
PLUGIN_NAME = markdown
PLUGIN_VERSION = 2.0.0
MAKEDIR = build
HOMEDIR = tmp
SRCDIR = src
PKGDIR = pkg
SYNTAX = $(MAKEDIR)/syntax/$(PLUGIN_NAME).vim
@hallison
hallison / weblog.rb
Created September 18, 2009 22:29
Example of how to use Sinatra::Mapping
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
require 'sinatra/mapping' # only this line for use mapping!
map :root, "blog" # /blog/
map :entries, "posts" # /blog/posts
map :tags, "labels" # /blog/labels
mapping :entry => "posts/:entry_id", # /blog/posts/id-for-post
@hallison
hallison / config.ru
Created August 6, 2009 16:19
Example of the Rackup file for a Sinatra application using Sinatra::Mapping extension.
require 'rubygems'
require 'sinatra'
require 'sinatra/mapping'
require 'blogware'
run Sinatra::Application