Skip to content

Instantly share code, notes, and snippets.

<?php
$db = new PDO('mysql:host=localhost;dbname=randomplaces', 'root', '');
for ($i=0; $i<500; $i++) {
$lat = rand(35,47).'.'.rand();
$lng = rand(9,20).'.'.rand();
$url = "https://maps.googleapis.com/maps/api/geocode/json?sensor=false&latlng=".$lat.",".$lng;
$json = json_decode(file_get_contents($url),1);
@kopiro
kopiro / ti-resize
Last active August 29, 2015 13:56
Ti-Resize
#!/bin/bash
# How to install
# curl https://gist.github.com/kopiro/8859612/raw -o /usr/local/bin/ti-resize
# How to use
# Put all your assets @2x in your $TITANIUM_PROJECT/assets
# Open Terminal
# ti-resize (in your Titanium Project directory)
@kopiro
kopiro / Fake-"Save-image"-with-background-size.markdown
Created February 17, 2014 15:50
A Pen by Flavio De Stefano.
@kopiro
kopiro / center-map-annotations-collection.js
Last active August 29, 2015 13:57
Center a map in Titanium + Underscore && Collections
var bb = [
_.min($$.pluck('lat')), _.min($$.pluck('lng')),
_.max($$.pluck('lat')), _.max($$.pluck('lng'))
];
$.map.region = {
latitude: (bb[0]+bb[2])/2,
longitude: (bb[1]+bb[3])/2,
latitudeDelta: 1.4*(bb[2]-bb[0]),
longitudeDelta: 1.4*(bb[3]-bb[1])
};
@kopiro
kopiro / localize.php
Created March 20, 2014 09:08
Geocoding
<?php
function get_coords_from_address($address) {
$url = sprintf("https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=%s", urlencode($address));
$res = file_get_contents($url);
if (empty($res)) {
throw new Exception("Empty response");
}
@kopiro
kopiro / parse-ini-string.php
Created March 24, 2014 09:03
Parse an INI string
<?php
function parse_ini_string($s) {
$S = []; $ls = '';
foreach (explode("\n", $s) as $l) {
if (preg_match("/\[(.+?)\]/", $l, $q)) {
$ls = $q[1]; $r[$ls] = [];
} elseif (preg_match("/(.+?)\=\"(.+?)\"/", $l, $q)) {
$S[$ls][$q[1]] = $q[2];
}
@kopiro
kopiro / TiUISwitch.m
Last active August 29, 2015 13:57
Set the tint color to "Switch" element - Titanium
/* Edit this file adding: ~/Library/Application Support/Titanium/mobilesdk/osx/3.2.2.GA/iphone/Classes/TiUISwitch.m */
-(void)setOnTintColor_:(id)color {
if ([color isKindOfClass:[UIColor class]]) {
[[self switchView] setOnTintColor:color ];
} else {
TiColor *ticolor = [TiUtils colorValue:color];
[[self switchView] setOnTintColor: [ticolor _color ] ];
}
}
@kopiro
kopiro / TiUIView.m
Last active August 29, 2015 13:57
Set the shadow for all Titanium Elements
/* Add to this file: ~/Library/Application Support/Titanium/mobilesdk/osx/3.2.2.GA/iphone/Classes/TiUIView.m */
-(void)setShadow_:(id)args
{
if (args != nil) {
self.layer.masksToBounds = NO;
if ([args objectForKey:@"shadowOffset"] != nil) {
CGPoint p = [TiUtils pointValue: [args objectForKey:@"shadowOffset"]];
CGSize shadowOffset = {p.x,p.y};
@kopiro
kopiro / Localize.php
Last active August 29, 2015 13:57
Localize models in Laravel with an Artisan Command
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class Localize extends Command {
protected $name = 'localize';
protected $description = 'Set the coordinates';
@kopiro
kopiro / fix-textarea-titanium.js
Created April 1, 2014 08:03
Fix TextArea.hintText property in #Titanium
/*
Fix TextArea.hintText property
*/
exports.createTextArea = function(args) {
var $textArea = Ti.UI.createTextArea(args);
if (args.hintText) {
$textArea.originalColor = $textArea.color || '#000';
if (!$textArea.value) {
$textArea.applyProperties({