Skip to content

Instantly share code, notes, and snippets.

View kosso's full-sized avatar

Kosso kosso

View GitHub Profile
@kosso
kosso / appnet_annotations.php
Created September 2, 2012 03:20
Adding annotations to an App.net post using PHP
<?php
// # Adding annotations to an App.net post using PHP
// Kosso - alpha.app.net/kosso
// Do what you like with it.
$ACCESS_TOKEN = 'BLahbLAHl1234BLAHBLAHBLAH';
$post_text = "Hello. This post has annotations";
@kosso
kosso / gist:3846020
Created October 6, 2012 20:27
Titanium hack : add insetcomplete event to setContentInsets - edit to TiUITableView.m
-(void)setContentInsets_:(id)value withObject:(id)props
{
UIEdgeInsets insets = [TiUtils contentInsets:value];
BOOL animated = [TiUtils boolValue:@"animated" properties:props def:NO];
void (^setInset)(void) = ^{
[tableview setContentInset:insets];
};
if (animated) {
double duration = [TiUtils doubleValue:@"duration" properties:props def:300]/1000;
[UIView animateWithDuration:duration animations:setInset completion:^(BOOL finished){
@kosso
kosso / gist:3877780
Created October 12, 2012 07:24
Making sure people log out of web-authed apps.
- (void)clearWebViewCookies:(NSMutableArray*)cleardomain
{
NSLog(@"[INFO] called webView clearWebViewCache to clear : %@", [cleardomain objectAtIndex:0]);
for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
//NSLog(@"[INFO] cookie for : %@",[cookie domain]);
if([[cookie domain] isEqualToString:[cleardomain objectAtIndex:0]]) {
//NSLog(@"[INFO] deleting cookie for : %@",[cookie domain]);
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
}
$.ajax({
beforeSend: function (req){
req.setRequestHeader("Authorization: Bearer", access_token);
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
},
type: "POST",
url: "https://alpha.app.net/oauth/access_token",
dataType:"json",
data:"grant_type=delegate&delegate_client_id=THECrAzYAppLIcATIOnWhICHaPAiNintHEaSS123",
success:function(data){
@kosso
kosso / avatar.php
Last active December 13, 2015 20:19
PHP to upload an avatar image to App.net
<?
// App.net Avatar uploader
// @Kosso
$access_token = 'AQAAAAAAAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$file_path = 'some_hilarious.gif';
$mime_type = 'image/gif';
@kosso
kosso / gist:5034300
Last active December 14, 2015 05:19
PHP to create an App.net streaming endpoint.
<?
// To create an App.net stream ...
$access_token = "YOUR_DEVELOPER_APP_ACCESS_TOKEN";
// to get an App Access token, see here : http://developers.app.net/docs/authentication/flows/app-access-token/
/*
$ch = curl_init();
@kosso
kosso / gist:5596339
Created May 17, 2013 01:24
Is BST in effect?
function isBSTinEffect(){
var d = new Date();
var lSoM;
// Loop over the 31 days of March for the current year
for(var i=31; i>0; i--){
var tmp = new Date(d.getFullYear(), 2, i);
// If it's Sunday
if(tmp.getDay() == 0){
// last Sunday of March
lSoM = tmp;
@kosso
kosso / gist:5596362
Created May 17, 2013 01:32
Some handy Ti CommonJS module functions
// Various useful functions.
function dateformat (format, timestamp) {
var that = this,
jsdate, f, formatChr = /\\?([a-z])/gi,
formatChrCb,
// Keep this here (works, but for code commented-out
// below for file size reasons)
//, tal= [],
@kosso
kosso / gist:6528020
Created September 11, 2013 18:46
Titanium test for iOS versioning
function isiOSVersionOrHigher(major_version)
{
if (Titanium.Platform.name == 'iPhone OS')
{
var version = Titanium.Platform.version.split(".");
var major = parseInt(version[0],10);
// can only test this support on a 3.2+ device
if (major >= major_version)
{
return true;
@kosso
kosso / app.js
Last active December 23, 2015 04:59
Fun with Ti.UI.iOS.NavigationWindow !
/*
Fun with NavigationWindow!
creates random coloured windows which create buttons which create random coloured windows which create buttons which...
you get the picture ;)
Required : Titanium SDK 3.1.3 or higher.
Kosso