Skip to content

Instantly share code, notes, and snippets.

@therealjohn
therealjohn / gist:9340477
Created March 4, 2014 04:50
Post Image and Tweet
public void PostImageAndTweetToTwitter()
{
if (SLComposeViewController.IsAvailable (SLServiceKind.Twitter)) {
var post = new NSString("Testing Social Framework!");
var twitterRequest = SLRequest.Create(SLServiceKind.Twitter,
SLRequestMethod.Post,
NSUrl.FromString("https://upload.twitter.com/1/statuses/update_with_media.json"),
NSDictionary.FromObjectAndKey(post, new NSString("status"))
);
var accountStore = new MonoTouch.Accounts.ACAccountStore();
var accType = accountStore.FindAccountType(ACAccountType.Facebook);
var accounts = accountStore.FindAccounts(accType);
var post = new NSString("Hello Facebook!");
if(accounts.Count() > 0)
{
var accountType = accountStore.FindAccountType(ACAccountType.Facebook);
accountStore.RequestAccess(accountType, null, (granted, error) => {
class DataTaskDelegate : NSUrlSessionDataDelegate
{
NSUrlSessionHandler This { get; set; }
public DataTaskDelegate(NSUrlSessionHandler that)
{
this.This = that;
}
public override void DidReceiveChallenge(NSUrlSession session, NSUrlSessionTask task, NSUrlAuthenticationChallenge challenge, Action<NSUrlSessionAuthChallengeDisposition, NSUrlCredential> completionHandler)
@therealjohn
therealjohn / gist:c658d6c087847360afdc
Created July 1, 2014 23:58
UIImage FixOrientation
public static UIImage FixOrientation(this UIImage image)
{
UIImage fixedImage = image;
// No-op if the orientation is already correct
if (image.Orientation == UIImageOrientation.Up) return image;
// We need to calculate the proper transformation to make the image upright.
// We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.
CGAffineTransform transform = CGAffineTransform.MakeIdentity();
@therealjohn
therealjohn / gist:7138336
Last active December 26, 2015 10:39
BTProgressHUD issue.
// Same results in all the ViewDidLoad, Appear, WillAppear, etc.
// The "Loading" dialog only shows for ~2ish seconds, then disappears. It disappears before the Dismiss();
public override void LoadView ()
{
base.LoadView ();
BTProgressHUD.Show("Loading");
try {
LoadSomething().ContinueWith(task => { // 10 Second task
@therealjohn
therealjohn / AsyncHelper.cs
Created December 15, 2016 16:46 — forked from rid00z/AsyncHelper.cs
This code can be used to task a async task and run it without the async part.
public static class AsyncHelper
{
private static readonly TaskFactory _myTaskFactory = new
TaskFactory(CancellationToken.None,
TaskCreationOptions.None,
TaskContinuationOptions.None,
TaskScheduler.Default);
public static TResult RunSync<TResult>(Func<Task<TResult>> func)
{
public class Program
{
static HttpListener listener;
static HttpListenerContext context;
private const int bufferSize = 4096;
public static void Main()
{
listener = new HttpListener("http", 8500);
listener.Start();
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/