Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@usainicola
usainicola / checkbox.php
Created June 5, 2020 01:00
Checkbox boilerplate - input
<?php
if (!defined('ABSPATH')) exit;
function checkbox($data=array()) {
$instance = '_'.uniqid();
$text = $data['text'] ?? '';
$checked = $data['checked'] ?? '';
$name = $data['name'] ?? '';
$class = $data['class'] ?? '';
ob_start('ob_gzhandler');
?>
@usainicola
usainicola / gist:f245b26f75764e8c4f3203c782c343bf
Created December 15, 2019 02:00
Search Replace Linux recursive subdirectories sed
find . -type f -exec sed -i 's/search/replace/g' {} +
@usainicola
usainicola / gist:38f89c05d0300e612defc7c5545c7128
Created June 25, 2019 11:37
Toggle Hide Scroll max-height
<div class="interactive">
<div class="toggle">
<p class="waves-effect">CLICK ME</p>
</div>
<div class="hideable">
<p>I wrap the content. Lorem what?</p>
</div>
</div>
<style type="text/css">
@usainicola
usainicola / gist:a1567b5af56367656c49645cbf774e27
Last active May 21, 2019 02:10
php backup zip current folder
<pre>
<?php
$path = realpath(__DIR__);
echo "<p>Zipping...</p>";
$zip = new ZipArchive();
$zip->open(dirname(__FILE__).'.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
foreach ($files as $name => $file) {
if ($file->isDir()) {
echo $name . "\r\n";
function distance(lat1, lon1, lat2, lon2) {
var p = 0.017453292519943295; // Math.PI / 180
var c = Math.cos;
var a = 0.5 - c((lat2 - lat1) * p)/2 +
c(lat1 * p) * c(lat2 * p) *
(1 - c((lon2 - lon1) * p))/2;
return 12742 * Math.asin(Math.sqrt(a)); // 2 * R; R = 6371 km
}
<?php
function distance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo) {
$rad = M_PI / 180;
$theta = $longitudeFrom - $longitudeTo;
$dist = sin($latitudeFrom * $rad) * sin($latitudeTo * $rad) + cos($latitudeFrom * $rad) * cos($latitudeTo * $rad) * cos($theta * $rad);
return acos($dist) / $rad * 60 * 1.852;
}
<?php
// column post image
function add_thumb_column($cols) {
$cols['thumbnail'] = 'Image';
return $cols;
}
function add_thumb_value($column_name, $post_id) {
$width = (int) 120;
@usainicola
usainicola / gist:d41d27c6d3b9e927f588a548e067819e
Created December 13, 2018 18:13
wp ajax get template part
<?php
function ajax_get_template_part() {
check_ajax_referer('ajax_get_template_part','nonce');
$part = esc_attr($_POST['template_part']);
if (!$part) {return;}
get_template_part($part);
die();
}
add_action( 'wp_ajax_nopriv_ajax_get_template_part', 'ajax_get_template_part' );
@usainicola
usainicola / gist:61a80a3dc675a25e2b9c8ffc2509527a
Created November 12, 2018 16:48
ripple, waves effect, button
.waves-effect {
position: relative;
overflow: hidden;
display: inline-block;
}
.ripple {
width: 0;
height: 0;
border-radius: 50%;
background: rgba(255, 255, 255, 0.4);