Skip to content

Instantly share code, notes, and snippets.

@dhoko
dhoko / gist:4329127
Last active December 9, 2015 21:18
Dynamically displaying input values using Javascript & CSS ::after
/*
Display value with ::after (CSS)
input[type="range"] {position: relative}
input[type="range"]::after {
content: attr(value);
position: absolute;
left: 105%;
top: 0;
color: #555
@dhoko
dhoko / gist:4593324
Last active December 11, 2015 11:28
Mon debug JS
var debug = true;
function trace(o, message){
if(navigator.userAgent.indexOf('MSIE') >= 0) {
return false;
}
if(debug){
if(message) console.group(message);
if(o instanceof Array){
@dhoko
dhoko / gist:4673729
Last active December 11, 2015 22:59
Minimize each JS files in a directory using Uglify-js
for i in * ; do uglifyjs $i -m -o "$(echo $i | cut -d . -f 1).min.js" ; done
@dhoko
dhoko / gist:4673807
Created January 30, 2013 14:56
Fuuuuuu JavaScript
alert(([{}][-1] + "")[4] + ([{}][3] + "")[~-1]+ ([{}][3] + "")[~-1]+ ([{}][3] + "")[~-1]+ ([{}][3] + "")[~-1]+ ([{}][3] + "")[~-1]+ ([{}][3] + "")[~-1]+ ([{}][3] + "")[~-1])
@dhoko
dhoko / gist:4673825
Created January 30, 2013 14:57
Ciao Gnome - Session Quit X
/usr/bin/gnome-session-quit --no-prompt
@dhoko
dhoko / gist:5115561
Created March 8, 2013 10:25
RGB 2 HEX
var rgb2Hex = function(r) {
var t = "#", n = r.split("(")[1].split(")")[0].split(",");
t += parseInt(n[0]).toString(16) + parseInt(n[1]).toString(16) + parseInt(n[2]).toString(16);
return t
}
@dhoko
dhoko / gist:5487602
Created April 30, 2013 09:22
VanillaJS toogle && changeClass
var toggle = function (r,className1) {
var regex = new RegExp("(?:^|\\s+)" + className1 + "(?:\\s+|$)");
r.className = (regex.test(r.className)) ? r.className.replace(regex," ") : r.className + ' '+className1;
return r.className;
};
var changeClass = function (r,className1,className2) {
var regex = new RegExp("(?:^|\\s+)" + className1 + "(?:\\s+|$)");
if( regex.test(r.className) ) {
@dhoko
dhoko / gist:5487610
Created April 30, 2013 09:24
trim() - JavaScript
String.prototype.trim=function(){return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');};
@dhoko
dhoko / gist:5671907
Created May 29, 2013 17:01
Convert color
var color = {
rgb : function() {
var color = [Math.floor(Math.random()*256),Math.floor(Math.random()*256),Math.floor(Math.random()*256)];
return 'rgb('+color.join(',')+')';
},
rgb2Hex : function(color) {
var hex = "#",
c = color.split('(')[1].split(')')[0].split(',');
hex += parseInt(c[0]).toString(16)+parseInt(c[1]).toString(16)+parseInt(c[2]).toString(16);
@dhoko
dhoko / gist:5720577
Created June 6, 2013 10:19
JavaScript ucFirst
function ucFirst(string) {
return string.charAt().toUpperCase() + string.slice(1);
}
/*
ucFirst('bonjour') => Bonjour
*/