Skip to content

Instantly share code, notes, and snippets.

View sergio-ivanuzzo's full-sized avatar

Sergio Ivanuzzo sergio-ivanuzzo

View GitHub Profile
@SleepWalker
SleepWalker / swipe.js
Created September 30, 2015 04:59
A simple swipe detection on vanilla js
var touchstartX = 0;
var touchstartY = 0;
var touchendX = 0;
var touchendY = 0;
var gesuredZone = document.getElementById('gesuredZone');
gesuredZone.addEventListener('touchstart', function(event) {
touchstartX = event.screenX;
touchstartY = event.screenY;
@Phoenix2k
Phoenix2k / gist:7980936
Created December 16, 2013 01:12
Convert RGB(A) values to #hexdecimal using jQuery.css()
// Convert RGB(A) values to #hexdecimal using jQuery.css()
// Original: http://jsfiddle.net/DCaQb/
// Note: This will not work on browsers which return 'color names' instead of rgb(a) values (i.e. IE8)
function rgba2hex( color_value ) {
if ( ! color_value ) return false;
var parts = color_value.toLowerCase().match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/),
length = color_value.indexOf('rgba') ? 3 : 2; // Fix for alpha values
delete(parts[0]);
for ( var i = 1; i <= length; i++ ) {
parts[i] = parseInt( parts[i] ).toString(16);
@Graceas
Graceas / FormErrorsSerializer.php
Created September 10, 2013 06:26
Symfony 2 Form Error Serializer. May be used for AJAX form validation. Allows tree and flat array styles for errors.
class FormErrorsSerializer {
public function serializeFormErrors(\Symfony\Component\Form\Form $form, $flat_array = false, $add_form_name = false, $glue_keys = '_')
{
$errors = array();
$errors['global'] = array();
$errors['fields'] = array();
foreach ($form->getErrors() as $error) {
$errors['global'][] = $error->getMessage();