Skip to content

Instantly share code, notes, and snippets.

View EpokK's full-sized avatar

Richard EpokK

View GitHub Profile
@EpokK
EpokK / manual.js
Last active August 29, 2015 14:02
Manual lowercase / uppercase
String.prototype.manualLowercase = function(s) {
return (typeof s === 'string') ? s.replace(/[A-Z]/g, function (ch) {
return String.fromCharCode(ch.charCodeAt(0) | 32)
}) : s;
};
String.prototype.manualUppercase = function (s) {
return (typeof s === 'string') ? s.replace(/[a-z]/g, function (ch) {
return String.fromCharCode(ch.charCodeAt(0) & ~32)
}) : s;
@EpokK
EpokK / capitalize.js
Created June 14, 2014 12:34
An AngulaJS directive to force uppercase in input
angular.module('myApp')
.directive('capitalize', function () {
return {
require: 'ngModel',
link: function(scope, element, attrs, modelCtrl) {
var capitalize = function(inputValue) {
if(angular.isDefined(inputValue)) {
var capitalized = inputValue.toUpperCase();
if(capitalized !== inputValue) {
modelCtrl.$setViewValue(capitalized);
@EpokK
EpokK / filter.js
Created May 23, 2014 06:27
Pour bold une value dans une chaine via un filter AngularJS
.filter('bold', function() {
return function(str, object) {
return String(str).replace(new RegExp('(^|\\s)(' + object.value + ')(\\s|$)', 'ig'), '$1<b>$2</b>$3');
};
})
@EpokK
EpokK / properApply.js
Created May 9, 2014 08:50
Pour appeler correctement $scope.$apply
$scope.properApply = function(callback) {
var phase = this.$root.$$phase;
if(phase !== '$apply' && phase !== '$digest') {
$scope.$apply(callback);
}
};
@EpokK
EpokK / bin2hex.js
Last active August 29, 2015 13:56
bin2hex like php function
function bin2hex (s) {
// From: http://phpjs.org/functions
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfixed by: Onno Marsman
// + bugfixed by: Linuxworld
// + improved by: ntoniazzi (http://phpjs.org/functions/bin2hex:361#comment_177616)
// * example 1: bin2hex('Kev');
// * returns 1: '4b6576'
// * example 2: bin2hex(String.fromCharCode(0x00));
// * returns 2: '00'
@EpokK
EpokK / snippets.json
Created January 30, 2014 10:04
Snippet Infomaniak pour Infomaniak
// start
@EpokK
EpokK / originalTarget.js
Created January 29, 2014 09:59
Best way to get the Original Target
var originalTarget = event.target || event.srcElement || event.originalTarget;
@EpokK
EpokK / getStandardOffsetUTC.php
Last active January 3, 2016 13:29
How to retrieve timezone offset from GMT+0 in php?
<?php
public function getStandardOffsetUTC($timezone)
{
if($timezone == 'UTC') {
return '';
} else {
$timezone = new DateTimeZone($timezone);
$transitions = array_slice($timezone->getTransitions(), -3, null, true);
@EpokK
EpokK / capture.js
Created January 14, 2014 08:17
Take screenshot at single viewport size using CasperJS
var screenshotUrl = 'http://example.com/'
var casper = require("casper").create({
viewportSize: {
width: 1024,
height: 768
}
});
if (casper.cli.args.length < 1) {
@EpokK
EpokK / countCSSRules.js
Last active December 19, 2016 21:32
countCSSRules : pour compter le nombre de règle CSS sur une page web.
function countCSSRules() {
var results = '',
log = '';
if (!document.styleSheets) {
return;
}
for (var i = 0; i < document.styleSheets.length; i++) {
countSheet(document.styleSheets[i]);
}
function countSheet(sheet) {