Skip to content

Instantly share code, notes, and snippets.

Avatar
🛠️
Work, work!

Renan Lazarotto RenanLazarotto

🛠️
Work, work!
View GitHub Profile
@RenanLazarotto
RenanLazarotto / count_recursive.php
Created Jan 25, 2021
PHP - Recursively count subarray(s) size
View count_recursive.php
<?php
// Sample array. From now own I'll just use lyrics :D
$array = [
"name" => "John Doe",
"document" => "01234567890",
"age" => "29",
"sex" => "male",
"addresses" => [
[
"street" => "Jane Doe St.",
@RenanLazarotto
RenanLazarotto / asymmetric_flatten.php
Created Jan 15, 2021
PHP "flatten" asymmetric arrays
View asymmetric_flatten.php
<?php
/**
* If you want people to love you, don't do this to your data.
*
* Sample input array
*/
$array = [
"key1" => "NOME",
"key2" => "RG",
"key3" => "CPF",
@RenanLazarotto
RenanLazarotto / file_download.php
Last active Jan 14, 2021
PHP Download file using curl
View file_download.php
<?php
function fileDownload($url, $destination, $headers) {
$ch = curl_init($url);
$tempnam = tempnam($destination, 'chtmp_');
$fp = fopen($tempnam, 'wb+');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
// set the headers if needed
@RenanLazarotto
RenanLazarotto / basic_auth.php
Created Jan 13, 2021
Simple copy-and-paste function to return a base64-encoded basic access token.
View basic_auth.php
<?php
/**
* Returns a base64 enconded string to use as basic auth token
*
* @param string $user Username
* @param string $password Password
*
* @return string Base64-encoded string
*/
private function basicAuth($user, $password) {
@RenanLazarotto
RenanLazarotto / clean_string.php
Created Jan 6, 2021
PHP: Cleans a string by replacing spaces with hyphens and removing non-alphanumeric chars
View clean_string.php
<?php
function clean_string($string) {
return preg_replace('/[^A-Za-z0-9\-\n]/', '', str_replace(' ', '-', $string));
}
@RenanLazarotto
RenanLazarotto / array_flatten.php
Last active Jan 6, 2021
PHP: Flatten multidimensional array with key/value association
View array_flatten.php
<?php
function array_flatten($originalArray = null) {
if (!$originalArray) {
// doesn't make sense to you? for me neither, lets kill it before I have more ideas
$originalArray = [
'a' => 1, 'b' => 2, 'c' => 'aa', ['d' => 3, 'e' => 4, 'f' => 5, 'g' => 'bb', ['h' => 6, 'i' => 7], 'j' => 8, 'k' => 9],
'l' => 10,'m' => 11,'n' => 'cc', ['o' => 12, 'p' => 13, 'q' => 14, 'r' => 'dd', ['s' => 15, 't' => 16, 'u' => 'ee', ['v' => 17, 'w' => 18], 'x' => 19]],
'y' => 20
];
@RenanLazarotto
RenanLazarotto / jsGrid-custom-buttons.js
Last active Oct 2, 2019
jsGrid - Bootstrap 4 Edit/Delete/Save/Cancel buttons
View jsGrid-custom-buttons.js
{
type: "control",
// the base button class should be Bootstrap's btn class
buttonClass: 'btn',
// the buttons class should be one of the Bootstrap's button styles
editButtonClass: 'btn-outline-primary btn-sm',
deleteButtonClass: 'btn-outline-primary btn-sm',
updateButtonClass: 'btn-primary btn-sm',
@RenanLazarotto
RenanLazarotto / jsgrid-bootstrap-pagination.css
Created Jan 4, 2019
jsGrid Bootstrap 4 Pagination CSS Classes
View jsgrid-bootstrap-pagination.css
.jsgrid-pager {
padding-left: 0;
display: flex;
list-style: none;
border-radius: .25rem;
}
.jsgrid-pager-page, .jsgrid-pager-nav-button {
position: relative;
display: block;
@RenanLazarotto
RenanLazarotto / web.config
Last active Nov 22, 2018 — forked from nurbek-ab/web.config
IIS rewrite rule for Symfony 4 - this was the only file that I could find that actually helped me to get Symfony 4 to work.
View web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="TempRewriteToWeb" stopProcessing="false">
<match url="^(public/)?(.*)$" />
<action type="Rewrite" url="public/{R:2}" logRewrittenUrl="true" />
</rule>