Skip to content

Instantly share code, notes, and snippets.

View jwv's full-sized avatar

Jonathan Vicente jwv

View GitHub Profile
@jwv
jwv / ismobile.js
Created October 21, 2013 09:21
Detect Mobile Devices
var isMobile = {
    Android: function() {
        return navigator.userAgent.match(/Android/i);
    },
    BlackBerry: function() {
        return navigator.userAgent.match(/BlackBerry/i);
    },
    iOS: function() {
        return navigator.userAgent.match(/iPhone|iPad|iPod/i);
    },
wget -r -l 20 ftp://username:password@www.example.org/htdocs/*
@jwv
jwv / mail_subject.php
Created May 8, 2013 11:32
PHP: Set Unicode Character in Email Subject
<?php
// Code with trick
$subject = "I Love You ❤";
$updated_subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
mail("email@receiver.com",$updated_subject,"This email subject should not contain JUNK characters.");
@jwv
jwv / diffDayBetweenTwoDates.m
Created February 15, 2013 14:42
Objective-c: Calculate The Number Of Days Between Two Dates
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM-dd-yyy"];
// To use a specific start date
// NSDate *startDate = [formatter dateFromString:@"02-16-2013"];
// Start with todays date
NSDate *startDate = [NSDate date];
// End date
@jwv
jwv / .htaccess
Last active June 27, 2020 09:28
Apache: Maintenance mode
############################################
## 503 Maintenance mode
RewriteCond %{REQUEST_URI} !^/maintenance/
RewriteCond %{REMOTE_HOST} !^YOUR\.IP\.ADDRESS\.HERE$
RewriteCond %{REMOTE_HOST} !^127\.0\.0\.1$
RewriteRule .* index.php [R=503,L]
ErrorDocument 503 /maintenance/maintenance.html
@jwv
jwv / paypal_fees.php
Last active January 25, 2024 13:42
PHP: Paypal Fees
function paypalFees($sub_total, $round_fee) {
// Set Fee Rate Variables
$fee_percent = '3.4'; // Paypal's percentage rate per transaction (3.4% in UK)
$fee_cash = '0.20'; // Paypal's set cash amount per transaction (£0.20 in UK)
// Calculate Fees
$paypal_fee = ((($sub_total / 100) * $fee_percent) + $fee_cash);
if ($round_fee == true) {
@jwv
jwv / force_download.php
Created January 8, 2013 02:26
PHP: Force download
function downloadFile($file){
$file_name = $file;
$mime = 'application/force-download';
header('Pragma: public'); // required
header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
header('Content-Transfer-Encoding: binary');
@jwv
jwv / calc_distances.php
Created January 8, 2013 02:25
PHP: Calculate distances
function distance($lat1, $lon1, $lat2, $lon2, $unit) {
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);
if ($unit == "K") {
@jwv
jwv / Highlight_Words_In_A_String.php
Created December 18, 2012 14:29
PHP: Highlight Words In A String
<?php
function highlight($astring, $aword) {
if (!is_array ($aword) || !is_string ($astring) || empty ($aword) ) {
return false;
}
$aword = implode ('|', $aword);
return preg_replace ('@\b('.$aword.')\b@si', '<strong style="background-color:red">$1</strong>', $astring);
}
function crawlerDetect($user_agent)
{
$crawlers_agents = 'Google|msnbot|Rambler|Yahoo|AbachoBOT|accoona|AcioRobot|ASPSeek|CocoCrawler|Dumbot|FAST-WebCrawler|GeonaBot|Gigabot|Lycos|MSRBOT|Scooter|AltaVista|IDBot|eStyle|Scrubby';
return strpos($crawlers_agents , $USER_AGENT) === false)?0:1;
}