Skip to content

Instantly share code, notes, and snippets.

View RobertoNovelo's full-sized avatar

Roberto Novelo RobertoNovelo

  • Roboflow
  • Guadalajara, Jalisco, México
View GitHub Profile
@RobertoNovelo
RobertoNovelo / gist:bcb6fa3fa4d18d067117
Created October 6, 2015 14:15
Random, unique, alphanumeric string with defined length
function crypto_rand_secure($min, $max)
{
$range = $max - $min;
if ($range < 1) return $min; // not so random...
$log = ceil(log($range, 2));
$bytes = (int) ($log / 8) + 1; // length in bytes
$bits = (int) $log + 1; // length in bits
$filter = (int) (1 << $bits) - 1; // set all lower bits to 1
do {
$rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes)));
@RobertoNovelo
RobertoNovelo / Paypal Rest API Codeigniter
Last active July 28, 2020 12:59
CodeIgniter 3.x Paypal Rest API Authorize Capture Wrapper
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once(BASEPATH . '../application/libraries/PayPal-PHP-SDK/autoload.php');
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Api\Capture;
use PayPal\Api\Authorization;
use PayPal\Api\Amount;
use PayPal\Exception\PayPalConnectionException;