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: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)
@yairEO
yairEO / gist:7468454
Last active September 26, 2016 09:27
Sublime3 key settings
[
{ "keys": ["ctrl+x"], "command": "cut" },
{ "keys": ["ctrl+d"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete Line.sublime-macro"} },
{ "keys": ["ctrl+shift+s"], "command": "reveal_in_side_bar"},
{
"keys": ["ctrl+alt+a"], "command": "align_tab",
"args" : {"user_input" : ":/f"}
}
]
@yairEO
yairEO / gist:7468471
Created November 14, 2013 15:12
Sublime3 user settings
{
"highlight_modified_tabs": true,
"highlight_line": true,
"caret_style": "phase",
"wide_caret": true,
"fade_fold_buttons": false,
"bold_folder_labels": true,
"ignored_packages":
[
"Vintage"
@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 / jsbin.nujus.js
Last active August 30, 2023 17:26
auto-generates month names in any locale
var months = [];
for( var i = 0; i < 12; i++ ){
months.push( new Date(0,i).toLocaleString({},{month:'short'}) );
// you can also pass a local like : "en-US" instead of an empty object `{}`.
// an empty object triggers the system's auto-detection
}
console.log(months);
@yairEO
yairEO / gist:9c3b53bbfb00c0ff6c13
Last active December 24, 2018 21:26
MOD-10 validator in javascript
var validateNum = function(num){
num = num.replace(/-/g,'');
var calc, i, check, checksum = 0, r = [2,1]; // alternating routing table
// iterate on all the numbers in 'num'
for( i=num.length-1; i--; ){
calc = num.charAt(i) * r[i % r.length];
//console.log(num.charAt(i), r[i % r.length], [calc]);
// handle cases where it's a 2 digits number