Skip to content

Instantly share code, notes, and snippets.

View lucasmezencio's full-sized avatar
:bowtie:
Neeeeeeeeerd

Lucas Mezêncio lucasmezencio

:bowtie:
Neeeeeeeeerd
View GitHub Profile
@lucasmezencio
lucasmezencio / bash-for-loop.sh
Created November 12, 2024 11:19
Bash Scripting Loops Basics
# Bash for loop
for i in /etc/*; do
echo "${i}"
done
# Same as above (alternate syntax)
# also works with other loop structures
for i in /etc/*
do
echo "${i}"

Keybase proof

I hereby claim:

  • I am lucasmezencio on github.
  • I am lucasmezencio (https://keybase.io/lucasmezencio) on keybase.
  • I have a public key ASCP5PplAC7HIgLFDK7ELdC8rhbkfIorXt0NPD03kjnjxwo

To claim this, I am signing this object:

The Boy/Girl Scout Rule

It’s not enough to write the code well. The code has to be kept clean over time. We’ve all seen code rot and degrade as time passes. So we must take an active role in preventing this degradation.

The Boy Scouts of America have a simple rule that we can apply to our profession.

Leave the campground cleaner than you found it.

If we all checked-in our code a little cleaner than when we checked it out, the code simply could not rot. The cleanup doesn’t have to be something big. Change one variable name for the better, break up one function that’s a little too large, eliminate one small bit of duplication, clean up one composite if statement.

@lucasmezencio
lucasmezencio / SLUG.md
Last active October 31, 2024 15:46
Creating URL slugs properly in PHP (including transliteration for UTF-8)

Creating URL slugs properly in PHP (including transliteration for UTF-8)

The point to use a slug (semantic URL) besides of improve the SEO of your articles is to prevent that the user, at the creation of for example an article, it uses special characters that aren't allowed in a URL, appropiate the usage etc. What target usage means, is context dependent.

In this article, you'll learn how to slugify a string in PHP properly, including (or not) support (conversion) for cyrilic and special latin characters.

Slugify in PHP

The following function exposes a simple way to convert text into a valid slug:

Verifying that +lucasmezencio is my blockchain ID. https://onename.com/lucasmezencio
@lucasmezencio
lucasmezencio / ToArrayExtension.php
Last active September 3, 2015 20:03 — forked from ajaxray/ToArrayExtension.php
A simple twig extension that adds a to_array filter. It will convert an object to array so that you can iterate over it's properties
<?php
// src/YourApp/Bundle/YourBundle/Twig/ToArrayExtension.php
namespace Appcito\Bundle\CoreBundle\Twig;
/**
* A simple twig extension that adds a to_array filter
* It will convert an object to array so that you can iterate over it's properties
*/
class ToArrayExtension extends \Twig_Extension
@lucasmezencio
lucasmezencio / post-receive
Last active August 29, 2015 14:26
git post-merge hook : update / install composer packages & composer itself
#!/bin/bash
# thanks http://www.jenssegers.be/blog/46/deploying-websites-with-git-and-composer-
# replace folder
cd "`dirname $0`/../../application/config"
# Check if a composer.json file is present
if [ -f composer.json ]; then
@lucasmezencio
lucasmezencio / MySQL.UPDATE.SELECT.sql
Created November 19, 2013 22:48
MySQL UPDATE SELECT
UPDATE tableA AS A
LEFT JOIN tableB AS B on (A.name_a = B.name_b)
SET
A.update_date = B.insert_date
@lucasmezencio
lucasmezencio / gist:7013188
Created October 16, 2013 19:16
Mongo Export
mongoexport --collection collection --db db --csv --out collection.csv --fields field1,field2,field3
@lucasmezencio
lucasmezencio / jQuery.UTF-8.js
Last active May 3, 2018 22:51
A way to manipulate UTF-8 strings in jQuery.
;(function($, undefined) {
$.extend({
toUTF8 : function(text) {
text = text.replace(/\r\n/g,"\n");
var output = [];
for (var n = 0 ; n < text.length ; n++) {
var c = text.charCodeAt(n);