Skip to content

Instantly share code, notes, and snippets.

View mohamedmansour's full-sized avatar
✔️
Available

Mohamed Mansour mohamedmansour

✔️
Available
View GitHub Profile
@mohamedmansour
mohamedmansour / fit_adjust.js
Created May 31, 2012 22:27
FIT Algorithm for resizing photos.
/**
* Adjust the resolution by scaling the height and width to fit the current
* width and height of the pane.
*
* @param {string} originalResolution the resolution in object format
* @param {string} maxResolutionthe resolution in object format
*
* @author Mohamed Mansour (http://mohamedmansour.com)
*/
var adjustResolution = function(originalResolution, maxResolution) {
@mohamedmansour
mohamedmansour / mediator.js
Created May 25, 2012 16:33
JavaScript Mediator Pattern
Utils = {};
/**
* Mediator pattern based on previous work by @rpflorence, depends on underscore :)
*
* Subscribe to an event:
* Utils.mediator.subscribe('FOO', onFoo);
* function onFoo(data) {alert(data.bar);};
*
* Fire an event:
@mohamedmansour
mohamedmansour / zerg_rush_google_cheat.js
Created April 27, 2012 22:14
Cheat Code to defeat the Google Zerg Rush!
// Mohamed Mansour 2012 http://mohamedmansour.com
var initEvent = function(element, str) {
var clickEvent = document.createEvent('MouseEvents');
clickEvent.initEvent(str, true, true);
element.dispatchEvent(clickEvent);
};
var simulateClick = function(element) {
initEvent(element, 'mousedown');
initEvent(element, 'click');
@mohamedmansour
mohamedmansour / unignore-all-bookmarklet.js
Created April 26, 2012 03:12
Bookmarklet for Google+ to auto unignore people
javascript:(function() {
// This is evil.
var global = {};
global.unignoredCount = 0;
global.IGNORE_DIALOG_SELECTOR = '.Yy.eoTope.b-w.Kz';
global.IGNORE_LINK_SELECTOR = '.k-U-C.k-EoqIId';
global.ACTIONS_DROP_SELECTOR = '.c-wa-Da.b-a.b-a-G.Po4Sz.Vy.c-q-o-a';
global.ACTIONS_IGNORE_SELECTOR = 'div[id=":16"]';
global.LOADING_SELECTOR = '.jb.dp';
global.VALID_URL_NAMESPACE = '^https://plus.google.com/(u/\\d+/)?circles';
@mohamedmansour
mohamedmansour / resize_override.js
Created April 15, 2012 18:26
Override the Resize Event from a given site, so you can reuse it and dispatch it!
/**
* Overrides the Resize Event handler if exists so we can call that resize callback.
* This is useful if websites relayout on resize events in case you are changing the
* DOM. Or perhaps doing some animations.
*
* @usage
* // Whenever your ready, it is best to inject this at the beginning.
* ResizeHijack.inject();
*
* // Then you fire the resize event and if that website has any resize it will call it.
@mohamedmansour
mohamedmansour / plus-injection.js
Created April 14, 2012 05:28
MutationSummary example for MutationObservers
// Keep track of the observers so we could clean up.
var previousObserver = null;
var currentObserver = null;
// Observe when the stream panel has changed. In Google+, the streampanel gets
// swapped when viewing another stream. It gets added, old one gets removed, and
// the new one's visibility is shown.
var summaryObserver = new MutationSummary({
callback: handleChanges,
queries: [{ element: "div[guidedhelpid='streamcontent']" }]
@mohamedmansour
mohamedmansour / port_check.sh
Created April 13, 2012 18:20
Checks if a port is active, and if so, queries which server is running.
#!/bin/sh
# Mohamed Mansour (http://mohamedmansour.com)
if [ $# -ne 1 ]; then
echo "Usage: port_checker <port>"
exit 1
fi
PORT=$1
@mohamedmansour
mohamedmansour / ldap_test.php
Created March 24, 2012 00:35
Testing LDAP in PHP
<?php
$ds = @ldap_connect(ldap_host);
if ($ds) {
$r = @ldap_bind($ds, 'mmansour@DOMAIN', 'bad');
if ($r) {
echo "Success";
}
else {
echo "Failed";
}
@mohamedmansour
mohamedmansour / main.py
Created February 29, 2012 00:46
Auto Move your mouse to keep Google+ Hangout alive.
#!/usr/bin/python
import win32api, win32con
import threading
class AutoMouseMove(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.event = threading.Event()
@mohamedmansour
mohamedmansour / manifest.json
Created February 12, 2012 00:13
Chrome Extension to transfer the current selected webpage text to the popup
{
"name": "Selected Text",
"version": "0.1",
"description": "Selected Text",
"browser_action": {
"default_title": "Selected Text",
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [