Skip to content

Instantly share code, notes, and snippets.

View prashantvc's full-sized avatar
:octocat:
Working

Prashant Cholachagudda prashantvc

:octocat:
Working
View GitHub Profile
@prashantvc
prashantvc / GammaFunction
Created February 28, 2012 17:16
Gamma function
double Gamma(double x)
{
if (x < 0)
{
return double.PositiveInfinity;
}
// Gamma(x) = (x-1)! so add 1, to make user gets
// expected result, I really don't want use increamental operator here.
@prashantvc
prashantvc / Node.cs
Created June 5, 2012 06:13
Create hierarchical structure from Dropbox delta api
//Author casperOne
public class Node
{
private readonly IDictionary<string, Node> _nodes = new Dictionary<string, Node>();
public string Name { get; set; }
public string Path { get; set; }
public IDictionary<string, Node> Nodes
{
fs.iRotated += (object dSender, EventArgs de) => {
Debug.WriteLine("________________________________________________________");
Debug.WriteLine("The modal view just rotated....");
Debug.WriteLine("My current orientation (UIApplication.SharedApplication.StatusBarOrientation.ToString()) = " + UIApplication.SharedApplication.StatusBarOrientation.ToString());
Debug.WriteLine(string.Format("My screen resolution is: Width = {0} Height = {1}",
this.View.Bounds.Width.ToString(),
this.View.Bounds.Height.ToString()));
var fsSender = (FlipsideViewController) dSender;
@prashantvc
prashantvc / ActiveWindows.cs
Created January 18, 2013 15:35
Periodically checks if app is idle for particular interval. (MonoTouch)
public class ActiveWindows:UIWindow
{
NSTimer idleTimter;
double idleTimeInterval;
public MyWindows (RectangleF frame):base(frame)
{
idleTimeInterval = 10; //Change the idle time
idleTimter =
NSTimer.CreateScheduledTimer (idleTimeInterval, WindowIdleNotification);
@prashantvc
prashantvc / UIViewToImage.cs
Last active December 11, 2015 20:39
Extension method to convert UIView to UIImage
public static class Extensions
{
public static UIImage ToImage (this UIView view)
{
RectangleF canvasRect = view.Bounds;
UIGraphics.BeginImageContextWithOptions (canvasRect.Size, false, 0.0f);
CGContext ctx = UIGraphics.GetCurrentContext ();
ctx.FillRect (canvasRect);
view.Layer.RenderInContext (ctx);
@prashantvc
prashantvc / AssetIncludeWorkaround.cs
Created February 22, 2013 12:53
WebView - URL mechanism is broken - passing parameters does not work. http://code.google.com/p/android/issues/detail?id=17535#c100
using System;
using System.IO;
using Android.App;
using Android.Content;
using Android.Content.Res;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Webkit;
var email = new Intent(Android.Content.Intent.ActionSendto);
email.SetType("text/html");
email.PutExtra(Android.Content.Intent.ExtraSubject, "Subject here");
email.PutExtra(Android.Content.Intent.ExtraText,
Html.FromHtml("<p><b>Some Content</b></p><small><p>More content</p></small>"));
StartActivity(Intent.CreateChooser(email, "Email:"));
@prashantvc
prashantvc / gist:5213961
Last active March 28, 2018 20:59
Send email with multiple attachments (Xamarin.Android)
public static void Email(Context context, string emailTo, string emailCC, string subject, string emailText, List<string> filePaths)
{
var email = new Intent(Intent.ActionSendMultiple);
email.SetType("text/plain");
email.PutExtra(Intent.ExtraEmail, new string[]{emailTo});
email.PutExtra(Intent.ExtraCc, new string[]{emailCC});
var uris = new List<IParcelable>();
filePaths.ForEach(file=> {
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.Dialog;
namespace TwoLayerDialog
{
@prashantvc
prashantvc / gist:5554830
Last active December 17, 2015 04:59
Sets the last modified date time to file
private static readonly DateTime Jan1st1970 = new DateTime
(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public static long CurrentTimeMillis()
{
return (long) (DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
}
public static DateTime GetDateFromMilliSeconds(long milliseconds)
{