Skip to content

Instantly share code, notes, and snippets.

@ozzieperez
ozzieperez / NumericValidationBehavior.cs
Created February 14, 2015 15:16
Xamarin.Forms Behavior Example
//Add functionality to visual elements without subclassing.
//Xamarin.Form controls can have a list of Behaviors.
public class NumericValidationBehavior : Behavior<Entry>
{
protected override void OnAttachedTo(Entry entry)
{
entry.TextChanged += OnEntryTextChanged;
base.OnAttachedTo(entry);
}
@ozzieperez
ozzieperez / Xamarin.Forms Accessibility-ChangeFocusedElement.cs
Last active August 29, 2015 14:15
Xamarin.Forms Accessibility - Change the default element selected when screen changes.
// Change default element selected when the screen changes.
// In the view controller...
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear (animated);
//pass in the object to get focus
UIAccessibility.PostNotification(UIAccessibilityPostNotification.ScreenChanged, myObject);
}
@ozzieperez
ozzieperez / ListShuffle.cs
Created February 26, 2015 09:42
Randomly shuffles items in a list
public static class ListShuffle
{
public static void Shuffle<T>(this IList<T> list)
{
Random rng = new Random();
int n = list.Count;
while (n > 1)
{
n--;
int k = rng.Next(n + 1);
@ozzieperez
ozzieperez / BPROP
Created March 17, 2015 22:03
Xamarin.Forms code template for bindable properties
public static readonly BindableProperty $name$Property = BindableProperty.Create<$owner$,$type$>(p => p.$name$, default($type$));
public $type$ $name$
{
get { return ($type$)GetValue($name$Property); }
set { SetValue($name$Property, value); }
}$end$
@ozzieperez
ozzieperez / syncDrives.sh
Created June 13, 2015 03:01
Sync 2 drives or directories
# Syncs a destination with a source.
# -a is basically "backup mode"
# -v is verbose, which shows each file that gets copied
# --delete will delete a file in the destination if it is not in the source
sudo rsync -av --delete /Volumes/MyDrive1/ /Volumes/MyDrive2/
@ozzieperez
ozzieperez / GetIndexPathFromCellEvent.cs
Created July 16, 2015 18:00
Gets the indexPath of a cell based on the coordinate point of the event
public NSIndexPath GetIndexPathFromCellEvent(object sender)
{
var point = ((UIButton)sender).ConvertPointToView(((UIButton)sender).AccessibilityActivationPoint, TableView);
var indexPath = TableView.IndexPathForRowAtPoint(point);
return indexPath;
}
@ozzieperez
ozzieperez / Flip Card with graceful degradation
Last active December 14, 2015 06:29
Flip Card With Graceful Degradation. Dependencies jQuery and Modernizr (can be optional). The only thing used from Modernizr is it looks for the "csstransforms3d" class to handle degradation.
<html class="csstransforms3d">
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<style>
/* CARDS
*****************************************************/
.card {
/* styling */
width: 200px;
height: 200px;
@ozzieperez
ozzieperez / Masonry with Flip cards and graceful degradation
Last active December 14, 2015 06:29
Masonry with gracefully degrading CSS transform flip cards. Dependencies are jQuery, Masonry, and Modernizr (only for csstransforms detection).
<html class="csstransforms3d1">
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/masonry/2.1.07/jquery.masonry.min.js"></script>
<style>
/* CARDS
*****************************************************/
.card {
/* styling */
@ozzieperez
ozzieperez / Test page for DOM Mutation Events
Created February 27, 2013 16:31
Test page to show support of DOM Mutation events
<html>
<!--
POC that detects DOM mutations on FF13+ and Chrome.
Uses MutationObserver, or DOM events as a fallback.
###################################################
For IE compatibility, replace:
myElement.addEventListener ('eventNameHere', callBackNameOrFunctionHere, false);
@ozzieperez
ozzieperez / Diff Backup Drives.sh
Last active December 20, 2015 20:25
Differences in 2 Drives
#Step One: Get the raw diffs... usually takes me an hour
grep -rq dir1 dir2 > rawdiffs.txt
#Step Two: Filter out the junk
grep Only rawdiffs.txt | grep -v '.Spotlight' | grep -v '.fseventsd' | grep -v '.DocumentRevisions' | grep -v '.DS_Store' | grep -v '.TemporaryItems' | sort > filteredDiffs.txt