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.xaml
Created May 10, 2014 00:14
Example of a popup control in Xaml with nice triangle
<Grid x:Name="LayoutRoot" Background="Transparent" Margin="0,55,0,0">
<Grid Background="White" Margin="0,10,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Margin="20" Background="Transparent">
<TextBlock Text="Listening" FontSize="36" Margin="0"/>
</StackPanel>
<StackPanel Grid.Row="1" Margin="20" Background="Transparent" VerticalAlignment="Bottom">
@mohamedmansour
mohamedmansour / gist:dc0c56820015e7f700e9
Last active August 29, 2015 14:02
Basic Cross Sandbox Communication for iOS 8 Action Extensions
// Append the transfer dom to the document.
var transferDOM = document.createElement('div');
transferDOM.style.display = 'none';
transferDOM.id = 'transferdom';
document.body.appendChild(transferDOM);
function injectScript(fn) {
var script = document.createElement('script');
script.appendChild(document.createTextNode('(' + fn + ')();'));
document.body.appendChild(script);
@mohamedmansour
mohamedmansour / Animation.xaml
Created July 3, 2014 19:02
Pulse Animation in XAML
<UserControl.Resources>
<Storyboard x:Name="StartAnimation">
<DoubleAnimation RepeatBehavior="Forever" Duration="0:0:1" To="360" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" Storyboard.TargetName="ProgressArc"/>
<DoubleAnimation Duration="0:0:0.5" RepeatBehavior="Forever" AutoReverse="True" From="25" To="35" Storyboard.TargetName="IndicatorRing" Storyboard.TargetProperty="StrokeThickness"/>
<DoubleAnimation Duration="0:0:0.5" RepeatBehavior="Forever" AutoReverse="True" From="350" To="370" Storyboard.TargetName="IndicatorRing" Storyboard.TargetProperty="Height"/>
<DoubleAnimation Duration="0:0:0.5" RepeatBehavior="Forever" AutoReverse="True" From="350" To="370" Storyboard.TargetName="IndicatorRing" Storyboard.TargetProperty="Width"/>
</Storyboard>
</UserControl.Resources>
@mohamedmansour
mohamedmansour / gist:33802d10fcf218e28fc6
Created March 29, 2015 01:04
JavaScript Decruft JSON
// In jQuery the easy thing to do when to decruft json responses if a javascript has:
//
// for (;;); {foo: 'bar'}
//
// Is to decruft it using ajax converters. Example
$.ajaxSetup({
converters: {
"text json": function(result) {
return JSON.parse(result.replace('for (;;);', ''));
task<GeolocationAccessStatus> geolocationAccessRequestTask(Windows::Devices::Geolocation::Geolocator::RequestAccessAsync());
geolocationAccessRequestTask.then([this](task<GeolocationAccessStatus> accessStatusTask)
{
// Get will throw an exception if the task was canceled or failed with an error
auto accessStatus = accessStatusTask.get();
if (accessStatus == GeolocationAccessStatus::Allowed)
{
// LOG: Waiting for update...
auto geolocator = ref new Windows::Devices::Geolocation::Geolocator();
@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 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: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();