Skip to content

Instantly share code, notes, and snippets.

@adinan-cenci
adinan-cenci / get-address-republica-virtual.php
Last active March 18, 2018 14:08
Dois serviços para a busca de endereço via CEP.
<?php
function republicaVirtualGetAddressByCep($cep, $format = 'json')
{
$ch = curl_init("http://cep.republicavirtual.com.br/web_cep.php?cep=$cep&formato=$format");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close ($ch);
return $data;
@adinan-cenci
adinan-cenci / prime-number.php
Last active November 16, 2019 10:30
Is x a prime number?
<?php
function isPrime($number)
{
// the only even prime number is 2
if (($number % 2 == 0 and $number != 2) or $number == 1) {
return false;
}
$finish = floor($number / 2); // the higher denominator of any number is its half
@adinan-cenci
adinan-cenci / cleaner-get-and-post.php
Last active August 12, 2018 17:21
A cleaner way to get $_POST and $_GET values
<?php
function getKey($key, &$array, $alternative)
{
if (! array_key_exists($key, $array)) {
return $alternative;
}
$value = empty($array[$key]) ? $alternative : $array[$key];
@adinan-cenci
adinan-cenci / censure-pinterest.js
Last active June 23, 2019 10:59
I hate Pinterest, so to be free from it I wrote this code to censure it from google search results with the help of "Injector" chrome extension
function getRidOfSearchResults()
{
for (let c of document.querySelectorAll('cite')){
if (! /pinterest\./.test(c.innerText)) {
continue;
}
var wrapper = getParentWithClass(c, 'g');
wrapper.style.opacity = 0.1;
@adinan-cenci
adinan-cenci / async-load-javascript.js
Last active July 6, 2019 11:52
Asynchronously load javascript files
async function loadScript(src)
{
return new Promise(async function(success, fail)
{
var script;
script = document.createElement('script');
script.async = true;
script.type = 'text/javascript';
script.onload = function(e)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script>
function onClick(e)
{
var x, width, perc;
@adinan-cenci
adinan-cenci / nodejs-simple-get-request.js
Last active April 29, 2019 23:31
A simple way of making a GET request, details such as headers may be modified
const http = require('http');
const https = require('https');
const url = require('url');
async function request(address, options = {})
{
var myUrl = url.parse(address);
var protocol = myUrl.protocol == 'https:' ? https : http;
var defaultOptions =
@adinan-cenci
adinan-cenci / __call-in-javascript.js
Last active July 7, 2023 06:10
How to emulate the php __call method in JavaScript
/**
* PHP's __call magic method is pretty useful. Unfortunately
* there is no equivalent in JavaScript, but it can be
* emulated with Proxy:
*/
magicMethodsProxy =
{
get: function(target, prop, receiver)
{
@adinan-cenci
adinan-cenci / drag-and-drop-example.markdown
Last active April 19, 2019 15:26
Drag and drop example
@adinan-cenci
adinan-cenci / social networks share buttons example.html
Last active October 31, 2021 15:14
How to share your page on social networks, meta data and links
<!DOCTYPE html>
<html lang="en">
<head>
<!--
In this example we'll see what meta data we need to write on our documents so any social network
may understand what our page is about, as well how to write links for the for sharing the page on
said social networks.
-->
<meta charset="UTF-8" />