Skip to content

Instantly share code, notes, and snippets.

View johnsardine's full-sized avatar

João Sardinha johnsardine

View GitHub Profile
var videoPlayerEmbed = jQuery('#playerID'); // Get player embed
var videoURL = videoPlayerEmbed.prop('src'); // Get current src
videoURL = videoURL.replace("&autoplay=1", ""); // Remove autoplay if exists
videoPlayerEmbed.prop('src',''); // Remove src to reset
videoPlayerEmbed.prop('src',videoURL); // Add src again, resetting
<?php
class BaseModel implements ArrayAccess {
public $attributes = array();
public $attributes_cast_as = array(); // key => closure returning the value
public $attributes_cast_as_integer = array();
public $attributes_cast_as_float = array();
public $attributes_cast_as_string = array();
@johnsardine
johnsardine / jquery.addClassWithAnimationContext.js
Last active July 26, 2016 09:58
jQuery add class with animation context. Like angularjs does when animating classes.
jQuery.fn.extend({
addClassWithAnimationContext: function(className, callback) {
return this.each(function(index, element) {
var self = jQuery(element);
// Exit if already has class
if ( self.hasClass(className) ) {
return;
}
@johnsardine
johnsardine / magicquotes.php
Created January 13, 2015 12:57
Disable magic quotes
// Disable magic quotes
if (get_magic_quotes_gpc()) {
$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
while (list($key, $val) = each($process)) {
foreach ($val as $k => $v) {
unset($process[$key][$k]);
if (is_array($v)) {
$process[$key][stripslashes($k)] = $v;
$process[] = &$process[$key][stripslashes($k)];
} else {
@johnsardine
johnsardine / coordinates_query.php
Last active August 29, 2015 14:08
WordPress: Query by coordinates
global $wpdb;
$selected_range_number = intval(100); // Km
$query_lat = str_replace(',', '.', strval($selected_address_lat_lng['lat']));
$query_lng = str_replace(',', '.', strval($selected_address_lat_lng['lng']));
$query_by_distance = sprintf('
SELECT
p.*,
@johnsardine
johnsardine / svg.md
Last active August 29, 2015 14:07
SVG on Websites

What have I learned so far?

(The android situations were experienced using 4.1.1)

The general support is good, as a background and with an svg file being used as src in an <img> tag.

However there are some issues still.

In android, SVG files used with <img> tags may appear stragely, or dont appear at all.

@johnsardine
johnsardine / index.html
Created September 16, 2014 09:05
Styling Selects Purely with CSS // source http://jsbin.com/cihor/11
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<style>
body { font-family: Helvetica; line-height: 1.3em; padding: 1em 10%; }
</style>
</head>
<body>
@johnsardine
johnsardine / permissions.sh
Created March 29, 2014 22:53
Generate 644 file permissions and 755 folder permissions
setfacl -d --recursive -m g::rx :dir
setfacl -d --recursive -m o::rx :dir
@johnsardine
johnsardine / db-save-import.php
Last active August 29, 2015 13:56
Save and/or import database into other server
<?php
$config = array(
'name' => 'Project Name',
'id' => 'project-id',
// (bool) If false, will only generate the sql file and will not import to destination server
'import' => true,
// Usually the remote connection