Skip to content

Instantly share code, notes, and snippets.

@wrabit
wrabit / slugify-with-transliteration-of-foreign-characters.php
Last active October 29, 2018 10:03
Simple URL Slugging Function with Transliteration
<?php
/**
* Slugifies a given string prepping it for usage as a URL string. Includes transliteration. Multi-byte ready for UTF-8.
* @param str $str Original url
* @param str $delimiter Separator to be used between words, default '-'
* @param bool $strtolower Keep existing case or convert all to lower, default true
* @return str Sluggified string;
*/
function slugify($str = '', $delimiter='-', $strtolower = true) {
$str = convert_foreign_characters($str);
@wrabit
wrabit / Detect the first and last post in the WordPress loop
Last active May 24, 2018 08:53
Detect the first and last post in Wordpress loop
if ( $wp_query->post_count == 0 ) {
// First post
}
if( ( $wp_query->current_post +1) == $wp_query->post_count ) {
// Last post
}
// detect first, even in paginated results
if( $wp_query->post_count == 0 && !is_paged() ) {
@wrabit
wrabit / _bootstrap_bulma_helpers.scss
Last active September 8, 2020 17:21
Bootstrap style responsive helper utilities for Bulma
/*
Start Bootstrap style responsive spacer helper
Utilities for spacing, text and float
*/
$spacer: 1rem !default;
$spacers: () !default;
$spacers: map-merge((
@wrabit
wrabit / _bulma_responsive_titles.scss
Last active April 8, 2019 08:10
Scaling responsive title sizing for Bulma
@include mobile {
.title.is-1 { font-size: $size-1 * 0.7 }
.title.is-2 { font-size: $size-2 * 0.7 }
.title.is-3 { font-size: $size-3 * 0.7 }
.title.is-4 { font-size: $size-4 * 0.7 }
.title.is-5 { font-size: $size-5 * 0.7 }
.title.is-6 { font-size: $size-6 * 0.7 }
}
@include tablet {
.title.is-1 { font-size: $size-1 * 0.8 }
@wrabit
wrabit / helpers.php
Last active March 18, 2020 18:44
PHP: Camel case to title case function
if (!function_exists('camel_to_title')) {
function camel_to_title($string = '')
{
// let's create spaces
$intermediate = preg_replace('/(?!^)([[:upper:]][[:lower:]]+)/', ' $0', $string);
// now upper case words
return mb_convert_case($intermediate, MB_CASE_TITLE);
}
}
@wrabit
wrabit / DuskConfigOverride.php
Last active February 22, 2023 16:15
Override Laravel config during Dusk tests
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class DuskConfigOverride
{
/**
@wrabit
wrabit / data_get.py
Last active February 6, 2024 13:33
Laravel inspired data_get() for python
def data_get(data, path, default=None):
"""
Retrieves a value from a nested data structure using "dot" notation.
This function is designed to work with dictionaries and tuples.
Parameters
----------
data : dict or tuple or None
The data structure from which to retrieve the value.
This can be a nested dictionary, tuple, or a combination of both.