Last active
September 30, 2015 08:57
-
-
Save psaia/1755885 to your computer and use it in GitHub Desktop.
Blog Examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var EventGarbageCollection = function ( context ) { | |
var instance = this; | |
this.collection = []; | |
this.context = context; | |
this.context.addEventListener('close', function ( ) { | |
instance.empty(); | |
}); | |
}; | |
EventGarbageCollection.prototype = { | |
collect : function ( evt, method ) { | |
this.collection.push([evt, method]); | |
}, | |
addEvent : function ( evt, method ) { | |
Ti.API.addEventListener(evt, method); | |
this.collect(evt, method); | |
}, | |
empty : function ( ) { | |
for ( var i = 0, len = this.collection.length; i < len; i++ ) { | |
Ti.API.removeEventListener( | |
this.collection[i][0], | |
this.collection[i][1] | |
); | |
} | |
this.collection = []; | |
} | |
}; | |
module.exports = EventGarbageCollection; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var self = Ti.UI.createWindow(args); | |
// Grab instance of class. | |
var egc = new (require('egc'))(self); | |
// Add events through the wrapper. | |
egc.addEvent('someEvent', function (){}); | |
egc.addEvent('anotherEvent', function (){}); | |
egc.addEvent('tresEvent', function (args){}); | |
// Call as usual... | |
Ti.API.fireEvent('someEvent'); | |
// More code... | |
// Maybe open some sub windows or modals... | |
// ... | |
// ... | |
self.close(); // And all of the above will be removed. Worry free. | |
// ------------------------ | |
// Other stuff you can do. | |
// ------------------------ | |
// Add event manually. | |
var func = function (foo) { alert('whoa'); }; | |
Ti.API.addEventListener('someEvent', func); | |
egc.collect('someEvent', func); | |
// Remove them all manually. | |
egc.empty(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="icon" data-icon="g"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var speed = 500, | |
from = { someProp:0, anotherProp:0 }, | |
to = { someProp:40, anotherProp:100 }; | |
$(from).animate(to, { | |
duration: speed, | |
step: function () { | |
// now we have access to this.someProp and | |
// this.anotherProp. | |
}, | |
complete: function () { | |
// called on complete | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Class for parsing svg files for json output. | |
* | |
* @author Pete Saia | |
*/ | |
class PeachSVG | |
{ | |
/** | |
* Takes a SVG file and converts it into an array or json object. | |
* | |
* PeachSVG::convert($filename); | |
* | |
* @param string to/the/file.svg | |
* @param boolean To output as json or an array. | |
* @return array | json | |
*/ | |
public static function convert($filename, $to_json = true) | |
{ | |
// Make sure the file was readable, if not die. | |
if ( ! $contents = file_get_contents($filename)) die('Could not open the file.'); | |
// Get array of graphical paths from svg content. | |
$graphical_paths = self::get_graphical_paths($contents); | |
// Iterates with every path in the svg file. | |
$path_iterator = 0; | |
// The output array. | |
$output = array(); | |
// Regex to match svg attributes. | |
$regex = '/\b(id|fill|d|name|stroke|stroke-width)\b=["|\']([^"\']*)["|\']/'; | |
// Loops through paths. | |
foreach ($graphical_paths as $path) | |
{ | |
// If matche not found & match doesn't contains a path attr, skip. | |
if ( ! preg_match_all($regex, $path, $matches) OR ! in_array('d', $matches[1])) | |
continue; | |
// Iterates for every attr found. | |
$attr_iterator = 0; | |
// Loops through attributes and adds to output array. | |
foreach ($matches[1] as $match) | |
{ | |
$output[$path_iterator][$match] = $matches[2][$attr_iterator]; | |
$attr_iterator++; | |
} | |
$path_iterator++; | |
} | |
// return either json or raw array. | |
return $to_json ? json_encode($output) : $output; | |
} | |
/** | |
* Extract graphical paths from SVG. These are the paths that are direct | |
* children of the <svg> tag. | |
* | |
* PeachSVG::get_graphical_paths($svg_content); | |
* | |
* @param string <svg>.....</svg> | |
* @return array | |
*/ | |
protected static function get_graphical_paths ($svg) | |
{ | |
// Remove all types of line breaks and tabs. | |
$contents = str_replace(array("\r", "\r\n", "\n", "\t"), '', $svg); | |
// Get all of the paths. | |
return explode('<path', $contents); | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@charset "UTF-8"; | |
@font-face { | |
font-family: "customFont"; | |
src:url("fonts/customFont.eot"); | |
src:url("fonts/customFont.eot?#iefix") format("embedded-opentype"), | |
url("fonts/customFont.ttf") format("truetype"), | |
url("fonts/customFont.svg#leafless") format("svg"), | |
url("fonts/customFont.woff") format("woff"); | |
font-weight: normal; | |
font-style: normal; | |
} | |
[data-icon]:before { | |
font-family: "customFont" !important; | |
content: attr(data-icon); | |
font-style: normal !important; | |
font-weight: normal !important; | |
font-variant: normal !important; | |
text-transform: none !important; | |
speak: none; | |
line-height: 1; | |
-webkit-font-smoothing: antialiased; | |
-moz-osx-font-smoothing: grayscale; | |
} | |
[class^="icon-"]:before, | |
[class*=" icon-"]:before { | |
font-family: "customFont" !important; | |
font-style: normal !important; | |
font-weight: normal !important; | |
font-variant: normal !important; | |
text-transform: none !important; | |
speak: none; | |
line-height: 1; | |
-webkit-font-smoothing: antialiased; | |
-moz-osx-font-smoothing: grayscale; | |
} | |
.icon-customFont:before { | |
content: "a"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"selector": "source.js, source.xml", | |
"cmd": [ | |
"titanium", "build", | |
"--platform", "ios", | |
"--project-dir", "${project}", | |
"--deploy-type", "test", | |
"--log-level", "trace" | |
], | |
"path" : "<paste $PATH here>" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"selector": "source.js, source.xml", | |
"cmd": [ | |
"titanium", "build", | |
"--platform", "ios", | |
"--project-dir", "${project}", | |
"--deploy-type", "test" | |
], | |
"path" : "<Put your echo $PATH here>" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var speed = 1500; | |
$("#myDiv").animate({ | |
// various css properties here. | |
}, speed); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment