Skip to content

Instantly share code, notes, and snippets.

View ImanMh's full-sized avatar
🏢
Working from office

Iman Mohamadi ImanMh

🏢
Working from office
View GitHub Profile
@ImanMh
ImanMh / save ssh passphrase.txt
Last active December 29, 2018 09:48
save ssh passphrase permanently
eval $(ssh-agent)
ssh-add
#you want to save for ever? run this one
ssh-add -k
@ImanMh
ImanMh / git-cheats
Created August 7, 2018 05:36
delete merged branches
git branch --merged | egrep -v "(^\*|master|development|beta)" | xargs git branch -d
@ImanMh
ImanMh / dateTime.js
Created April 23, 2018 10:49
Passing a day and a timezone offset and getting back local time.
const getLocalTime = (date, offset) => {
const utc = date.getTime() - (date.getTimezoneOffset() * 60000);
const corrected = new Date(utc + (3600000 * offset));
return {
hours: corrected.getHours(),
minutes: corrected.getMinutes(),
};
};
// Tehran Local Time
@ImanMh
ImanMh / irancell_sms_delete_trick.js
Created March 31, 2017 15:55
A trick to delete all Irancell 4G modem SMSs in the fastest possible way
//put a debugger where ajax_delete_sms_message calls del and type this in console
//del = function () {};
//this fuction is supper heavy and we are trying to bypass it
//one of the messages will be removed now inpect yes button again in next msg delete modal
//and type this snippet
//i is the id of first msg and j is a simple counter
var i = '1366';
var j = '0';
var timer = setInterval(function () {
@ImanMh
ImanMh / test cross origin cors
Created August 16, 2016 09:57
tests cross origin access or cors usinc curl
curl -I http://pathtosite.com
#this should contain Access-Control-Allow-Origin: header
@ImanMh
ImanMh / rangedRandom
Created February 13, 2015 20:58
Generates a random number between min and max
function makeRandom (min, max) {
return Math.floor( Math.random() * (max - min + 1) + min )
}
@ImanMh
ImanMh / singletone.js
Created August 9, 2014 12:16
simple single tone pattern in javascript
function factory() {
var highlander = {
name: 'MacLeod'
};
return {
get: function get() {
return highlander;
}
};
@ImanMh
ImanMh / objectToArray
Last active August 29, 2015 14:05
converst a javascript object into array, aka pure
convertObjectToArray = function (obj, mergedPropName) {
var arr = [];
for (prop in obj) {
if (!obj.hasOwnProperty(prop))
continue;
var newObj = obj[prop];
newObj[mergedPropName] = prop;
arr.push(newObj);
}
@ImanMh
ImanMh / QunitPending
Created July 27, 2014 12:27
Qunit missing pending test feature
QUnit.pending = function() {
QUnit.test('(Pending...) ' + arguments[0], function() {
QUnit.expect(0);//dont expect any tests
var li = document.getElementById(QUnit.config.current.id);
QUnit.done(function() {
li.style.background = '#FFFF99';
});
});
};
pending = QUnit.pending;
@ImanMh
ImanMh / pure-javascript-extend.js
Created June 24, 2014 15:07
Implemention of $.extendm _.extend method in pure JavaScript
//Originally by Ryan Lynch
function extend(){
for(var i=1; i<arguments.length; i++)
for(var key in arguments[i])
if(arguments[i].hasOwnProperty(key))
arguments[0][key] = arguments[i][key];
return arguments[0];
}