Skip to content

Instantly share code, notes, and snippets.

@dannycabrera
dannycabrera / Program.cs
Created August 21, 2019 20:15
FaxApp Program.cs
using Microsoft.Owin.Hosting;
using System;
using Twilio;
using Twilio.Rest.Fax.V1;
namespace FaxApp
{
class Program
{
static IDisposable _app = null;
@dannycabrera
dannycabrera / Util.cs
Created August 21, 2019 20:08
FaxApp Util.cs
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
namespace FaxApp
{
public class Util
{
public async Task<string> DownloadFile(string url)
@dannycabrera
dannycabrera / CallbackController.cs
Created August 21, 2019 19:54
FaxApp CallbackController.cs
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
@dannycabrera
dannycabrera / Startup.cs
Created August 21, 2019 19:50
FaxApp Startup
using Owin;
using System.Web.Http;
namespace FaxApp
{
class Startup
{
public void Configuration(IAppBuilder appBuilder)
{
// Configure Web API for self-host.
@dannycabrera
dannycabrera / gist:6802931
Created October 3, 2013 00:58
Xamarin.iOS URL schema to link to app's iTunes App Store page
UIApplication.SharedApplication.OpenUrl(new NSUrl("itms-apps://itunes.apple.com/app/idAPP_ID"))
@dannycabrera
dannycabrera / AsposePDFReplaceText.cs
Created June 26, 2018 20:49
Aspose.PDF ReplaceText method
public void ReplaceText(string sourcePDF, string destinationPDF, string textPhrase, string replacementText)
{
// Open document
using (Document pdfDocument = new Document(sourcePDF))
{
// Create TextAbsorber object to find all instances of the input search phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(textPhrase);
// Accept the absorber for all the pages
pdfDocument.Pages.Accept(textFragmentAbsorber);
@dannycabrera
dannycabrera / AwaitAlertAsync.cs
Last active June 14, 2018 14:10
Xamarin.Android await AlertDialog.Builder
await AlertAsync(this, "My Title", "My Message", "Yes", "No");
public Task<bool> AlertAsync(Context context, string title, string message, string positiveButton, string negativeButton)
{
var tcs = new TaskCompletionSource<bool>();
using (var db = new AlertDialog.Builder(context))
{
db.SetTitle(title);
db.SetMessage(message);
@dannycabrera
dannycabrera / AwaitAlertAsync.cs
Created June 14, 2018 13:49
Xamarin.Android await AlertDialog.Builder
public Task<bool> AlertAsync(Context context, string title, string message, string positiveButton, string negativeButton)
{
var tcs = new TaskCompletionSource<bool>();
using (var db = new AlertDialog.Builder(context))
{
db.SetTitle(title);
db.SetMessage(message);
db.SetPositiveButton(positiveButton, (sender, args) => { tcs.TrySetResult(true); });
db.SetNegativeButton(negativeButton, (sender, args) => { tcs.TrySetResult(false); });
@dannycabrera
dannycabrera / AppDelegate ReceivedRemoteNotification
Created March 25, 2014 19:32
AppDelegate ReceivedRemoteNotification Example
public override void ReceivedRemoteNotification (UIApplication application, NSDictionary userInfo)
{
processNotification(userInfo, false);
}
void processNotification(NSDictionary options, bool fromFinishedLaunching)
{
//Check to see if the dictionary has the aps key. This is the notification payload you would have sent
if (null != options && options.ContainsKey(new NSString("aps")))
{
@dannycabrera
dannycabrera / WriteWavHeader.cs
Last active June 1, 2018 22:16
Xamarin.Android Wave Header Method
using System;
using System.IO;
public void WriteWavHeader(string filePath, int sampleRate, short bitsPerSample, short channels)
{
using (var fs = File.Open(filePath, FileMode.Open, FileAccess.ReadWrite))
{
using (BinaryWriter writer = new BinaryWriter(fs, System.Text.Encoding.UTF8))
{
writer.Seek(0, SeekOrigin.Begin);