Skip to content

Instantly share code, notes, and snippets.

View pedrosancao's full-sized avatar
💭
Making the internet

Pedro Sanção pedrosancao

💭
Making the internet
View GitHub Profile
@pedrosancao
pedrosancao / uncheckable-radio.js
Created August 14, 2019 12:08
enable radio buttons to be unchecked both vanilla and jQuery
// iterate using Array method for compatibility
Array.prototype.forEach.call(document.querySelectorAll('[type=radio]'), function(radio) {
radio.addEventListener('click', function(){
var self = this;
// get all elements with same name but itself and mark them unchecked
Array.prototype.filter.call(document.getElementsByName(this.name), function(filterEl) {
return self !== filterEl;
}).forEach(function(otherEl) {
delete otherEl.dataset.check
})
@pedrosancao
pedrosancao / showdata.js
Created July 28, 2019 21:54
validate captcha and show data for google cloud functions with node
const https = require('https')
const querystring = require('querystring')
exports.showdata = (req, res) => {
const data = '___________________'
const captchaSecret = '________________________________'
const allowedOrigins = ['______________________________']
const verifyData = querystring.stringify({
secret : captchaSecret,
@pedrosancao
pedrosancao / vr.js
Last active July 27, 2019 16:15
iterar extrato VR
for (var i = 0, months = {}, d = new Date((new Date()).getFullYear(), 0, 1); i < 12; d.setMonth(++i)) {
months[d.toLocaleDateString('default', {month: 'long'}).replace(/^\w/, c => c.toUpperCase())] = ('0' + (i + 1)).substr(-2);
}
// inspecionar requisição anterior
var suffix = '______________/__';
var token = '____________';
var pages = 50;
var page = 1;
var data = [];
@pedrosancao
pedrosancao / Kernel.php
Last active June 12, 2019 12:48
Laravel localized URLs - POC for package
<?php
protected $routeMiddleware = [
//...
'locale' => \APP\Http\Middleware\LocaleRedirect::class,
//...
];
@pedrosancao
pedrosancao / ssl-params.conf
Last active March 24, 2019 03:12
SSL Apache configuration file
# generate CSR for multiple domains:
# https://www.endpoint.com/blog/2014/10/30/openssl-csr-with-alternative-names-one
# configuration for /etc/apache2/conf-available/ssl-params.conf
# full totorial available on
# https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-apache-in-ubuntu-16-04
# from https://cipherli.st/
# and https://raymii.org/s/tutorials/Strong_SSL_Security_On_Apache2.html
@pedrosancao
pedrosancao / encrypt.sh
Created September 10, 2018 13:47
openssl encrypt/decrypt script, requires public key in pem format
#!/bin/bash
if [ $1 == "-d" ]; then
if [ ! -r $2 ]; then
echo 'supply a valid input file to decrypt'
exit 1
fi
openssl rsautl -decrypt -inkey $HOME/.ssh/id_rsa -in $2 2> /dev/null
exit 0
fi
@pedrosancao
pedrosancao / parse_files.php
Last active October 27, 2015 12:29
Parses the PHP's $_FILES array when multiple file input is used, it will return an array as each file was from a different input. It also works when multiple and single inputs are mixed
<?php
/**
* Parses the PHP's $_FILES array when multiple file input is used, it will
* return an array as each file was from a different input. It also works
* when multiple and single inputs are mixed
*
* @author Pedro Sanção <pedro at sancao do co>
* @license MIT Licence
*/
<?php
/**
* Close open HTML tags and get the ones left open
*
* @author Pedro Sanção <pedro at sancao do co>
* @license MIT Licence
*
* @param string $html
* @return array tags without closing pair
@pedrosancao
pedrosancao / unitConvert.js
Last active August 29, 2015 14:26
convert pixels to other units of measurement back and forth, according to device DPI
/**
* Convert pixels to other units of measurement, according to device DPI
*
* @author Pedro Sanção <dev at sancao dot co>
* @license MIT
*/
var unitConvert = (function(){
var precision = 0
, _setPrecision = function(p) {
precision = p;
@pedrosancao
pedrosancao / isType.js
Last active August 29, 2015 14:16
A improved type verification function that avoid problems with instanceof and typeof, works with literals and across frames for JavaScript natives objects only
/**
* A improved type verification function that avoid problems with instanceof and typeof, works with literals and across frames
* for JavaScript natives objects only
*
* @author Pedro Sanção <dev at sancao dot co>
* @license GNU GPL v2
*
* @see http://stackoverflow.com/questions/203739/why-does-instanceof-return-false-for-some-literals?rq=1
* @see http://stackoverflow.com/questions/14391506/instanceof-operator-fails-when-passing-an-object-through-windows
*/