Skip to content

Instantly share code, notes, and snippets.

Avatar

Kosuke Isobe k0sukey

View GitHub Profile
@k0sukey
k0sukey / request.js
Created Aug 14, 2015
Titanium Ti.Network.HTTPClient wrapper, looks like npm/request
View request.js
// Inspired by npm/request
var _ = require('alloy/underscore')._;
function initParams(uri, options, callback) {
if (typeof options === 'function') {
callback = options;
}
var params = {};
if (typeof options === 'object') {
@k0sukey
k0sukey / TiNetworkHTTPClientProxy+Extend.m
Last active Aug 29, 2015
Extension, pick up the Ti.Network.HTTPClient 401 response on async
View TiNetworkHTTPClientProxy+Extend.m
// http://stackoverflow.com/questions/3912532/ios-how-can-i-receive-http-401-instead-of-1012-nsurlerrorusercancelledauthenti
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
-(NSNumber*)status
{
NSString *strError = [NSString stringWithFormat:@"%@", [[[self response] error] description]];
if ([strError rangeOfString:@"Code=-1012"].location != NSNotFound)
{
return NUMINTEGER(401);
}
@k0sukey
k0sukey / foo.js
Created Aug 28, 2014
bulksave method for Alloy collection
View foo.js
exports.definition = {
config: {
'columns': {
'bar': 'text'
},
'adapter': {
'type': 'sql',
'collection_name': 'foo'
}
},
@k0sukey
k0sukey / alloy.jmk
Last active Dec 8, 2016
Alloy built in underscore.js replace to lo-dash.js put your project folder app/assets/javascript/lodash.underscore.js
View alloy.jmk
task("pre:compile", function(event,logger) {
logger.info('----- PRE:COMPILE -----');
});
task("post:compile",function(event,logger){
logger.info('----- POST:COMPILE -----');
var fs = require('fs'),
path = require('path'),
platform = event.alloyConfig.platform === 'ios' ? 'iphone' : event.alloyConfig.platform; // Resources/iphone
@k0sukey
k0sukey / app > alloy.js
Last active Dec 12, 2015
fake css class with Alloy
View app > alloy.js
...
Alloy.Globals.CSS = function(view, name){
var css = require('css/css');
view.applyProperties(css[name]);
};
@k0sukey
k0sukey / alloy.jmk
Created Jan 17, 2013
Replace Resources/alloy/backbone.js, undercore.js
View alloy.jmk
task("pre:compile", function(event,logger){
});
task("post:compile",function(event,logger){
var fs = require("fs");
fs.writeFileSync(event.dir.resourcesAlloy + '/underscore.js', fs.readFileSync('path/to/underscore.js', 'utf8'));
var backbone = fs.readFileSync('path/to/backbone.js').toString();
fs.writeFileSync(event.dir.resourcesAlloy + '/backbone.js', backbone.replace(/require\("underscore"\)/, 'require("alloy/underscore")'));
@k0sukey
k0sukey / alloy.jmk (CoffeeScript)
Created Nov 17, 2012
Alloy with CoffeeScript / TypeScript
View alloy.jmk (CoffeeScript)
task("pre:compile", function(event,logger) {
var wrench = require("wrench"),
fs = require("fs"),
path = require("path"),
coffee = require("coffee-script");
event.alloyConfig.coffee = [];
wrench.readdirSyncRecursive(event.dir.home).forEach(function(target){
if (target.match(/\.coffee$/)) {
@k0sukey
k0sukey / app.js
Created Mar 30, 2012
As you like editor for TiShadow.
View app.js
/**
* Module dependencies.
*/
var express = require('express'),
io = require('socket.io'),
routes = require('./routes'),
fs = require('fs'),
path = require('path')
;
@k0sukey
k0sukey / app.js
Created Mar 14, 2012
filterablecamera CommonJS style.
View app.js
filterablecamera = require('filterablecamera').Filterablecamera({
squared: true,
showControls: true,
animated: false,
autohide: true,
saveToPhotoGallery: true,
quality: 'Photo',
backgroundImage: null
});
@k0sukey
k0sukey / app.js
Created Feb 29, 2012
like AssistiveTouch
View app.js
Ti.UI.setBackgroundColor('#fff');
var window = Ti.UI.createWindow({
navBarHidden: true
});
var assistiveTouch = require('ti.draggable').createView({
top: 0,
left: 0,
width: 48,