Skip to content

Instantly share code, notes, and snippets.

@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 / iosStringSize.cs
Created June 26, 2015 20:48
Xamarin IOS - Get the size of a string
//Method 1: No restrictions
((NSString)t.Text).GetSizeUsingAttributes(new UIStringAttributes {Font = t.Font});
//Method 2: Has to fit within a width
label.Frame = new CGRect(CGPoint.Empty, ((NSString)label.Text).GetBoundingRect(
new CGSize(width, nfloat.MaxValue),
NSStringDrawingOptions.UsesLineFragmentOrigin,
new UIStringAttributes { Font = label.Font},
null
).Size);
@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 / ViewAsImage.cs
Created July 31, 2015 21:50
Xamarin IOS - Returns a UIView as a UIImage
public static UIImage AsImage(this UIView view)
{
UIGraphics.BeginImageContextWithOptions(view.Bounds.Size, true, 0);
view.Layer.RenderInContext(UIGraphics.GetCurrentContext());
var img = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
return img;
}
@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
@ozzieperez
ozzieperez / zsh_on_ubuntu.md
Last active March 5, 2016 10:17 — forked from tsabat/zsh.md
Getting oh-my-zsh to work in Ubuntu
@ozzieperez
ozzieperez / killprocs.sh
Last active August 27, 2016 08:31
Kill a comma-delimited list of processes
#!/bin/bash
# ex: ./killprocs.sh Process1,Process2,Process3
# set the "internal field separator" variable (delimiter)
IFS=','
# read the delimited line into an array
read -ra PROCS <<< "$1"
# loop through the array
for i in "${PROCS[@]}"; do
# get the PID of the process
@ozzieperez
ozzieperez / bash-cheatsheet.sh
Created September 9, 2016 04:28 — forked from LeCoupa/bash-cheatsheet.sh
Bash CheatSheet for UNIX Systems
#!/bin/bash
#####################################################
# Name: Bash CheatSheet for Mac OSX
#
# A little overlook of the Bash basics
#
# Usage:
#
# Author: J. Le Coupanec
# Date: 2014/11/04
@ozzieperez
ozzieperez / mongoGroupAggregateHelper.js
Created September 16, 2016 01:44
Creates a $group object for Mongo aggregate that adds all the properties of a Model object and any other additions.
let Group = {
/*
* Description:
* Creates a $group object for Mongo aggregate that adds all the properties
* of a Model object and any other additions.
*
* Sample usage:
* MyCoolModel.aggregate({$match:{..}, {$group:Group.withModel(MyCoolModel, {count: { $sum: 1 }})} })
*
* Parameters: