Skip to content

Instantly share code, notes, and snippets.

// convert qa string to slug in JS
const toSlug = function (str) {
str = str.replace(/^\s+|\s+$/g, ""); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
const from = "âăãàáäâẽèéëêìíïîõòóöôùúüûñçșț·/_,:;";
const to = "aaaaaaaeeeeeiiiiooooouuuuncst------";
for (let i = 0, l = from.length; i < l; i++) {
str = str.replace(new RegExp(from.charAt(i), "g"), to.charAt(i));
@reddo
reddo / locations.php
Last active August 25, 2023 02:32
A directus.io custom endpoint to get distance based on coordinates. Put this file in `public/extensions/custom/endpoints/` and access it via `{{api_url}}/custom/locations?lat=LATITUDE_TO_CHECK_AGAINST&lng=LONGITUDE_TO_CHECK_AGAINST`
<?php
use Directus\Application\Http\Request;
use Directus\Application\Http\Response;
use Directus\Services\ItemsService;
use Zend\Db\Adapter\Adapter;
return [
// The endpoint path:
// '' means it is located at: `/custom/<endpoint-id>`
function custom_gform_confirmation( $confirmation, $form, $entry, $ajax ) {
if (!function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage') && !function_exists('qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage')) {
return $confirmation . "<br> not translated";
} else {
$confirmation = function_exists('qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage') ? qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage($confirmation) : qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($confirmation);
return $confirmation . "<br> translated";
}
}
add_filter( 'gform_confirmation', 'custom_gform_confirmation', 10, 4 );
@reddo
reddo / fullpage-update.js
Last active October 19, 2016 12:52
Added check for touch devices.
/**
* Determines the way of scrolling up or down:
* by 'automatically' scrolling a section or by using the default and normal scrolling.
*/
function scrolling(type, scrollable){
if (!isScrollAllowed.m[type]) {
return;
}
var firstTimeToTop = typeof scrollable.data('firstTimeToTop') === "undefined" ? true : scrollable.data('firstTimeToTop'), // get variable from data instance if it's set, otherwise set default.