Skip to content

Instantly share code, notes, and snippets.

@ttran4040
ttran4040 / gist:a7b5f08319e0b271ffdc
Last active August 29, 2015 14:03
Unirest Asynchronous Requests
NSDictionary* headers = @{@"accept": @"application/json"};
NSDictionary* parameters = @{@"parameter": @"value", @"foo": @"bar"};
[[UNIRest post:^(UNISimpleRequest* request) {
[request setUrl:@"http://httpbin.org/post"];
[request setHeaders:headers];
[request setParameters:parameters];
}] asJsonAsync:^(UNIHTTPJsonResponse* response, NSError *error) {
// This is the asyncronous callback block
NSInteger* code = [response code];
http://technet.rapaport.com/info/RapLink/
//1 - Authenticate with TechNet. The authentication ticket will be stored in $auth_ticket. Note this MUST be HTTPS.
$auth_url = "https://technet.rapaport.com/HTTP/Authenticate.aspx";
$post_string = "username=YOURUSERNAME&password=" . urlencode("YOURPASSWORD");
//create HTTP POST request with curl:
$request = curl_init($auth_url); // initiate curl object
curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
@ttran4040
ttran4040 / ObectiveCSerialization
Created July 7, 2014 00:28
Objective C Serialization
// RMSerialization.m
#import "RMContext.h"
@implementation RMContext
+ (NSString*) serializationPath
{
NSFileManager* fileManager = [[NSFileManager alloc] init];
NSString* bundleID = [[NSBundle mainBundle] bundleIdentifier];
@ttran4040
ttran4040 / gist:d8e9f7dce4f3213a3fa3
Created November 26, 2014 15:51
Swift Dispatch Async
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
//Code
}
@ttran4040
ttran4040 / gist:74a07380af8c76d1b3d4
Last active February 9, 2024 21:24
Check for Internet Connection (Swift)
import Foundation
import SystemConfiguration
public class Reachability {
class func isConnectedToNetwork() -> Bool {
var zeroAddress = sockaddr_in(sin_len: 0, sin_family: 0, sin_port: 0, sin_addr: in_addr(s_addr: 0), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0))
zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))
zeroAddress.sin_family = sa_family_t(AF_INET)
@ttran4040
ttran4040 / gist:700abc8d8152be099039
Last active August 29, 2015 14:10
Binary Search Tree Implementation in PHP
<?php
class Node {
public $info;
public $left;
public $right;
public $level;
public function __construct($info) {
$this->info = $info;
@ttran4040
ttran4040 / pinterest_v3
Created April 1, 2015 21:07
Pinterest V3 User & Board Pins
Pin for a specific Board:
https://api.pinterest.com/v3/pidgets/boards/{user_id}/{board}/pins/
Pin for a specific User:
http://api.pinterest.com/v3/pidgets/users/{user_id}/pins/
@ttran4040
ttran4040 / 0_reuse_code.js
Last active August 29, 2015 14:26
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ttran4040
ttran4040 / gist:aa5aba581c8061e6800d1681b55ac5a3
Last active February 28, 2018 14:26
Update Vagrant Ubuntu Time
Copy and paste the above script into a text file (I’ve named mine force-ntp-update).
On the command line, call chmod a+x /path/to/force-ntp-update to allow all users to execute the command.
If you’re the only user who should be able to execute the command, change the above to chmod u+x /path/to/force-ntp-update.
Move the script somewhere in your path: mv /path/to/force-ntp-update /usr/local/bin.
```
#!/bin/bash
# Forces an ntp update
# Fail fast (set -e will bail at first error)