Skip to content

Instantly share code, notes, and snippets.

Avatar
😊
I may be slow to respond.

Hallison Batista hallison

😊
I may be slow to respond.
View GitHub Profile
View gist:9dc0ecdec3190de9a115405f85ba654c
$(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 Feb 6, 2020
Deploys para vários sites usando o nome de domínio no nome do diretório
View sites.conf
# 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 Dec 16, 2019
JS - Parse JWT
View Decode 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 Feb 25, 2019
Order list items in Array
View array-order-items.js
Array.prototype.orderItems = function(newer, older) {
var list = new Array(...this)
return list.splice(newer - 1, 0, ...list.splice(older, 1))
}
View optparse-template.rb
#!/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 Jan 2, 2012 — forked from rkh/chat.rb
Simple Chat Application using the Sinatra Streaming API
View chat.rb
# 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 Jun 27, 2011
Vim-Markdown Makefile
View 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 / SparkLearn.java
Created Jun 6, 2011
Howto use a simple renderer for Spark-Java
View SparkLearn.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 / weblog.rb
Created Sep 18, 2009
Example of how to use Sinatra::Mapping
View weblog.rb
#!/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 Aug 6, 2009
Example of the Rackup file for a Sinatra application using Sinatra::Mapping extension.
View config.ru
require 'rubygems'
require 'sinatra'
require 'sinatra/mapping'
require 'blogware'
run Sinatra::Application
You can’t perform that action at this time.