Skip to content

Instantly share code, notes, and snippets.

@lomboboo
lomboboo / watermark.php
Last active November 30, 2021 13:07
PHP add watermark with centered diagonal text
<?php
// recursive search by pattern
function rsearch($folder, $pattern) {
$dir = new RecursiveDirectoryIterator($folder);
$ite = new RecursiveIteratorIterator($dir);
$files = new RegexIterator($ite, $pattern, RegexIterator::GET_MATCH);
$fileList = array();
foreach($files as $file) {
$fileList = array_merge($fileList, $file);
}
@lomboboo
lomboboo / generates.css
Last active October 23, 2018 15:39
SCSS margin/padding mixin with responsiveness
.mt-1 {
margin-top: 1rem; }
.pt-1 {
padding-top: 1rem; }
@media (min-width: 768px) {
.mt-sm-4 {
margin-top: 4rem; }
@lomboboo
lomboboo / gist:c78dd37f9aadc2f9ee28a538ed5ae8fc
Created March 2, 2018 16:19 — forked from lttlrck/gist:9628955
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@lomboboo
lomboboo / .htaccess
Created November 1, 2017 12:59
htaccess file - dynamic (subdirectories) removing html extension, redirecting filename.html to filename
RewriteEngine On
RewriteBase /
# %{ENV:BASE} is now subdirectory, ex. /folder/subfolder/
RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
RewriteRule ^(.*)$ - [E=BASE:%1]
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /(.+?)\.html[\s?] [NC]
RewriteRule ^ %1 [R=302,L,NE]
ssh-copy-id "user@server -p 1111"
@lomboboo
lomboboo / introrx.md
Created June 16, 2017 11:13 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
function _transliterate_to_ascii($str, $case = 0)
{
static $UTF8_LOWER_ACCENTS = NULL;
static $UTF8_UPPER_ACCENTS = NULL;
if ($case <= 0)
{
if ($UTF8_LOWER_ACCENTS === NULL)
{
$UTF8_LOWER_ACCENTS = array(
'à' => 'a', 'ô' => 'o', 'ď' => 'd', 'ḟ' => 'f', 'ë' => 'e', 'š' => 's', 'ơ' => 'o',
@lomboboo
lomboboo / get-attachment-id-by-url
Created May 18, 2017 13:10
Get attachment ID by attachment URL
get_attachment_id( $att_url ) {
global $wpdb;
$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE guid='%s';", $att_url ) );
return $attachment[0];
}
@lomboboo
lomboboo / json2csv.php
Last active April 11, 2017 10:07
Converts json to csv. If json is multidimensional - serializing it
<?php
/*
Plugin Name: json2csv
Description: Converts json to csv. If json is multidimensional - serializing it
Usage: Example is below code
Version: 0.1
Author: Lomboboo
*/
class JSON2CSV {
$url = 'http'.(isset($_SERVER['HTTPS'])?'s':'').'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];