Skip to content

Instantly share code, notes, and snippets.

View yairEO's full-sized avatar
🙂
Writing code

Yair Even Or yairEO

🙂
Writing code
View GitHub Profile
@yairEO
yairEO / gist:ee337e46173dcdfd0e78
Created June 16, 2014 12:27
fix for placeholders in old IE
(function($){
"use strict";
$.fn.fixPlaceholders = function(){};
if( $.support.placeholders )
return;
var selector = 'input[placeholder], textarea[placeholder]',
originalType;
@yairEO
yairEO / gist:c4a65143110529383f37
Created July 1, 2014 15:33
detect progressive jpeg loaded
// check if PROGRESSIVE image was loaded
var duration = 60,
interval = setInterval(checkImageLoaded, duration),
maxTime = 3000;
function checkImageLoaded(){
maxTime -= duration;
// image was loaded (or should have been)
if( photo.naturalWidth ){
clearInterval(interval);
@yairEO
yairEO / gist:0fafaddf2fa6718393c3
Created August 25, 2014 15:32
jQuery plugin - add temporary class name
$.fn.addTempClass = function(tempClass, duration){
if( !tempClass )
return this;
return this.each(function(){
var $elm = $(this);
$elm.addClass(tempClass);
setTimeout(function(){
$elm.removeClass(tempClass);
@yairEO
yairEO / gist:946afffee17fe38d9aec
Last active August 29, 2015 14:22
SASS - MIXIN - Triangle
// Triangle helper mixin (by Yair Even-Or)
// @param {Direction} $direction - Triangle direction, either `top`, `right`, `bottom` or `left`
// @param {Color} $color [currentcolor] - Triangle color
// @param {Length} $size [1em] - Triangle size
@mixin triangle($direction, $color: currentcolor, $size: 1em) {
$size: $size/2;
$transparent: rgba($color, 0);
$opposite: (top:bottom, right:left, left:right, bottom:top);
content: '';
@yairEO
yairEO / SassMeister-input.scss
Created August 11, 2015 21:42
Generated by SassMeister.com.
// ----
// Sass (v3.4.14)
// Compass (v1.0.3)
// ----
$icons-map: (add-user: '\e63e', remove-user: '\e63f', user: '\e628', search: '\e62e');
@each $key, $value in $icons-map {
.icon-#{$key}:before { content: #{$value}; }
}
function abbreviateNumber(value){
var newValue = value,
suffixes, suffixNum, shortValue, precision, dotLessShortValue;
if (value >= 1000) {
suffixes = ["", "k", "m", "b","t"];
suffixNum = Math.floor( (""+Math.round(value)).length/3 );
shortValue = '';
for (precision = 2; precision >= 1; precision--) {
shortValue = parseFloat( (suffixNum != 0 ? (value / Math.pow(1000,suffixNum) ) : value).toPrecision(precision));
dotLessShortValue = (shortValue + '').replace(/[^a-zA-Z 0-9]+/g,'');
@yairEO
yairEO / gist:6186034
Last active December 20, 2015 19:49
get Passport login details within socket.IO
io.sockets.on('connection', function (socket){
try{
var profileCookie = cookie.parse(socket.handshake.headers['cookie']),
profile;
if( profileCookie && profileCookie['connect.sess'] ){
profile = profileCookie['connect.sess'];
profile = JSON.parse(profile.slice(profile.indexOf('{'), profile.indexOf('}.') + 1));
}
}
catch(err){}
@yairEO
yairEO / gist:6340626
Created August 26, 2013 11:44
Check if a character is RTL or LTR
function isRTL(s){
var ltrChars = 'A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF'+'\u2C00-\uFB1C\uFDFE-\uFE6F\uFEFD-\uFFFF',
rtlChars = '\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC',
rtlDirCheck = new RegExp('^[^'+ltrChars+']*['+rtlChars+']');
return rtlDirCheck.test(s);
};
@yairEO
yairEO / gist:7030050
Last active December 25, 2015 19:49
scroll to position - jQuery plugin
////////////////////////////////////////
// Scroll To / jQuery plugin
//
// @author Yair Even Or
// @version 1.0.0 (April 3, 2013)
//
(function($){
"use strict";
var currentPos = 0,
@yairEO
yairEO / gist:7059388
Created October 19, 2013 18:09
move things in paralex on mouse move
// mouse move animations
$('.container').on('mousemove', moveSquares);
function moveSquares(e){
var mousex = (e.pageX - (e.currentTarget.clientWidth/2)) / e.currentTarget.clientWidth;
for( i in squares ){
if( i < 6)
squares[i].style.cssText = transform + ': translateX('+ Math.ceil(mousex*55) +'px)';
if( i >= 6 && i < 10)