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 / popup.html
Created September 23, 2010 02:33
Google Chrome Extension to figure out which image on the page is the largest.
<!DOCTYPE html>
<html>
<head>
<style>
body {
width: 300px;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
@mohamedmansour
mohamedmansour / Mail.java
Created September 26, 2010 02:05
Send an email in Java
// Email message
String toAddress = "someone@example.com";
String fromAddress = "hello@mohamedmansour.com";
String subject = "Hello Yahoo!"
String message = "From Java!";
// Auth.
String host = "smtp.mail.yahoo.com";
String port = "465";
String username = "foo";
@mohamedmansour
mohamedmansour / background.html
Created January 3, 2011 18:13
Google Chrome Extension to upload a locally stored image to imgurl API service.
<!DOCTYPE html>
<html>
<head>
<script>
const API_KEY = 'SOME_KEY';
/**
* Use HTML5 Canvas to get the image data
* @param {HTMLImageElement} img An Image Tag
@mohamedmansour
mohamedmansour / background.html
Created January 8, 2011 18:02
Google Chrome Extension to override the Notifications API usage.
<html>
<script>
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
var notificationObj = request.NotificationCallback;
if (notificationObj) {
if (notificationObj.url) {
// HTML Notification.
}
else {
// TEXT Notification
@mohamedmansour
mohamedmansour / background.html
Created January 9, 2011 07:07
Google Chrome Extension for No Browsing History
<!DOCTYPE html>
<html>
<head>
<script>
// Fired when a URL is visited, providing the HistoryItem data for that URL.
chrome.history.onVisited.addListener(function(historyItem) {
// Deletes all items from the history.
chrome.history.deleteAll(function() {});
});
</script>
@mohamedmansour
mohamedmansour / gist:803631
Created January 31, 2011 04:11
Get and Set localStorage from Content Script
// Content Script to save data.
chrome.extension.sendRequest({storage: 'foo', value: 'bar'});
// Content Script to get data.
chrome.extension.sendRequest({storage: 'foo'}, function(response) {
console.log('foo => ' + response.storage);
});
// Background Page
@mohamedmansour
mohamedmansour / gist:835093
Created February 19, 2011 14:45
Asynchronous Function Chaining
function doProcess() {
// do something;
funcA(data, /*callback*/ function () {
// do something;
funcB(data, /* callback*/ function () {
// do something;
funcC(data, /* callback*/ function () {
// do something;
funcD(data, /* callback*/ function () {
// do something;
@mohamedmansour
mohamedmansour / gist:835107
Created February 19, 2011 15:02
Asynchronous Function Queue
var function_queue = [
funcA,
funcB,
funcC,
funcD
];
function doNextAction() {
if (function_queue.length) {
var next_function_call = function_queue.shift();
next_function_call();
@mohamedmansour
mohamedmansour / gist:846017
Created February 27, 2011 08:22
Keyboard State Handler
<!DOCTYPE html>
<!-- Simple keyboard state handler, Vincent Scheib. -->
<!-- Adapted from http://www.cryer.co.uk/resources/javascript/script20_respond_to_keypress.htm -->
<html><body>
<table border="1" cellspacing="0">
<tbody><tr>
<th>KeyDown</th>
<th>KeyUp</th>
<th>KeyPress</th>
</tr>
@mohamedmansour
mohamedmansour / gist:854233
Created March 4, 2011 05:45
JAXB Example for Stackoverflow
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;