Skip to content

Instantly share code, notes, and snippets.

@Androguide
Androguide / tel-regex.js
Last active March 15, 2021 20:58
French phone number regex
var regex = new RegExp(/^[+](\d{3})\)?(\d{3})(\d{5,6})$|^(\d{10,10})$/);
regex.test('0612345678') // true
regex.test('06123456789') // false
regex.test('+33612345678') // true
regex.test('+330612345678') // true
regex.test('+3306123456789') // false
@Androguide
Androguide / uuid4.js
Created October 13, 2015 15:13
Generates a v4 UUID according to the spec
my.uuid4 = function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, my._uuid4);
};
// Cache callback to optimize perf
my._uuid4 = function(cc) {
var rr = Math.random() * 16 | 0; return (cc === 'x' ? rr : (rr & 0x3 | 0x8)).toString(16);
};
@Androguide
Androguide / BinaryTranslator.js
Created September 24, 2015 09:18
Converts decimal to binary and outputs a table of the powers of 2 for manual conversion
(function () {
"use strict";
window.BinaryTranslate = function (number) {
var binaryTable = [[], []];
var master = number;
var neighbour = nearestPowerOf2(number);
for (var i = neighbour; i >= 0; i--) {
binaryTable[0].push(Math.pow(2, i));
binaryTable[1].push(master - Math.pow(2, i) >= 0 ? 1 : 0);
@Androguide
Androguide / blackorwhite.js
Last active September 4, 2015 15:33
Get black or white color depending on background color for best readability. Based on the YIQ color-space contrast ratio.
function blackOrWhite(hexcolor) {
var color = hexcolor.substring(1);
hexcolor = color.length < 5 ? color + color : color;
var r = parseInt(hexcolor.substr(0, 2), 16);
var g = parseInt(hexcolor.substr(2, 2), 16);
var b = parseInt(hexcolor.substr(4, 2), 16);
var yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000;
return (yiq >= 125) ? '#333' : '#eee';
}
@Androguide
Androguide / ng-ie9.js
Created January 14, 2015 11:05
AngularJS fix for IE9
window.console = window.console || {};
window.console.log = window.console.log || function() {};
@Androguide
Androguide / bs-carousel.coffee
Last active August 29, 2015 14:05
Angular directive to encapsulate the Bootstrap carousel component: http://getbootstrap.com/javascript/#carousel
@Androguide
Androguide / bugdroid.html
Last active August 29, 2015 14:04
An Android mascot built with CSS
<!DOCTYPE html>
<html>
<head>
<title>CSS Bugdroid</title>
<link href='http://fonts.googleapis.com/css?family=Roboto:400,100,300' rel='stylesheet' type='text/css'>
<style type="text/css">
body {
padding: 40px;
@Androguide
Androguide / watch.html
Created July 15, 2014 16:02
CSS Watch
<!DOCTYPE html>
<html>
<head>
<title>CSS WATCH</title>
<link href='http://fonts.googleapis.com/css?family=Roboto:400,100,300' rel='stylesheet' type='text/css'>
<style type="text/css">
body {
background: #00bad2;
@Androguide
Androguide / paper-input.js
Created July 11, 2014 11:53
A directive providing native AngularJS 2-way data-binding support for Polymer's <paper-input> component
'use strict';
// Paper Input Directive
// ---------------------
// The AngularJS directive allowing to bind to Polymer's `<paper-input>` elements
// with Angular like they were standard HTML5 `<input>` elements, using the `ng-model` attribute
angular.module('Androguide').directive('paperInput', ['$parse', '$timeout', '$browser', function ($parse, $timeout, $browser) {
return {
restrict: 'E',
@Androguide
Androguide / init.environ.rc.in
Created April 19, 2014 12:43
PAC Rom support in /system/core/rootdir/init.environ.rc.in
export BOOTCLASSPATH /system/framework/core.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/framework-pac.jar:/system/framework/framework2.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/mms-common.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar:/system/framework/webviewchromium.jar:/system/framework/telephony-msim.jar