Skip to content

Instantly share code, notes, and snippets.

@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 / ReflectionExamples.cs
Last active May 20, 2022 08:19
Reflection Examples in C#
/*
This example shows how to dynamically load assembly, how to create object instance, how to invoke method or how to get and set property value.
Create instance from assembly that is in your project References
*/
//The following examples create instances of DateTime class from the System assembly.
// create instance of class DateTime
DateTime dateTime = (DateTime)Activator.CreateInstance(typeof(DateTime));
@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 / split_by_silence.sh
Last active May 11, 2020 16:03
Bash script to split an mp3 file from silent sections
#!/bin/bash
# file name to be split
input=$1
# text to prepend to the file name of the slices
prepend=$2
# counter for the slices
slice_counter=1
# current start
start=0
@ozzieperez
ozzieperez / run-detached-process.sh
Last active July 31, 2019 14:17
Ubuntu Linux: Run command independent/detached from your session so it continues after exiting
# run the command with nohup
nohup npm run my-process &
# check that it's running
jobs
# detach your session from that job
disown -h %1
@ozzieperez
ozzieperez / IOHelper.cs
Last active March 3, 2019 19:23
Xamarin.iOS - Get Special Folder Directory
public class IOHelper
{
public enum IosSpecialFolder
{
Documents,
Library,
Cache,
Preferences,
Tmp
}
@ozzieperez
ozzieperez / ISQLite.cs
Created February 14, 2015 14:38
SQLite for Xamarin.Forms Example
//db interface in shared pcl
using System;
using SQLite.Net;
namespace SampleApp
{
public interface ISQLite
{
SQLiteConnection GetConnection();
@ozzieperez
ozzieperez / trie.py
Created August 6, 2017 20:08 — forked from nickstanisha/trie.py
An object-oriented implementation of a "Trie" in Python
class Node:
def __init__(self, label=None, data=None):
self.label = label
self.data = data
self.children = dict()
def addChild(self, key, data=None):
if not isinstance(key, Node):
self.children[key] = Node(key, data)
else:
@ozzieperez
ozzieperez / lightsail-docker.sh
Created June 7, 2017 05:06 — forked from davidkryzaniak/lightsail-docker.sh
Auto-Install Docker on AWS Lightsail
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt-get update
sudo apt-get install -y linux-image-extra-$(uname -r) linux-image-extra-virtual
sudo apt-get install -y docker-engine
sudo service docker start
sudo docker pull php:5.6-apache
@ozzieperez
ozzieperez / .gitconfig
Created March 22, 2017 17:26 — forked from dahlbyk/.gitconfig
Windows Git Diff/Merge Tool Configuration
[alias]
dt = difftool
mt = mergetool
[diff]
tool = bc3
[difftool]
prompt = false
[difftool "bc3"]
cmd = \"c:/program files (x86)/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\"
[difftool "p4"]