Skip to content

Instantly share code, notes, and snippets.

@40
40 / formatNumbersFromCommas.as3
Created July 2, 2012 05:42
Formatting Numbers with Commas Function (Actionscript 3)
trace(formatNum(1000));
trace(formatNum(10000000));
trace(formatNum(1000000.39485));
 
function formatNum(num:Number):String {
    var newStr:String = "";
    var str:String = num.toString();
   
    var parts:Array = str.split(".");
    str = parts[0];
@40
40 / removeFirstChar.as3
Created July 2, 2012 05:44
Remove first character from string (AS3)
var someString:String = "_file";
trace(someString.substr(1));
/*
ouptuts:
file
*/
@40
40 / formatPhoneNum.as3
Created July 2, 2012 05:45
Phone Number Format TextField Automatically (AS3)
var phoneField:TextField = new TextField();
with (phoneField) {
    type=TextFieldType.INPUT;
    maxChars=12;
    restrict="0-9";
    border=true;
    width=100;
    height=20;
    x=y=20;
}
@40
40 / checkDataCoverage.js
Created July 19, 2012 00:16
BlackBerry WebWorks Wifi/Network Conn Check via HTML5
// Please add blackberry.system and blackberry.system.event feature IDs to config.xml
if (!blackberry.system.hasDataCoverage()) {
alert("This app requires access to internet for the content to work. Please turn on Wifi and restart this application");
}
else{
alert('Winning');
}
@40
40 / gist:3141242
Created July 19, 2012 07:05
Localizing BlackBerry WebWorks Applications: #Bookmark
http://devblog.blackberry.com/2012/06/internationalizing-webworks-app/
@40
40 / uniqArrayVals.js
Created July 19, 2012 08:13
Unique Values in Array
// Original Source: http://stackoverflow.com/questions/1960473/unique-values-in-an-array
// 1. Variation 1
var a = [1,5,1,6,4,5,2,5,4,3,1,2,6,6,3,3,2,4];
// note: jQuery's filter params are opposite of javascript's native implementation :(
var unique = $.makeArray($(a).filter(function(i,itm){
// note: 'index', not 'indexOf'
return i == $(a).index(itm);
@40
40 / pageSwipe.qml
Created July 25, 2012 21:54
Swipe Gesture Between Page in BB10 Cascades (code)
Page {
content: Container {
SegmentedControl {
Option { id: option1; text: "Container1"; value: "option1"; selected: true }
Option { id: option2; text: "Container2"; value: "option2" }
onSelectedIndexChanged: {
if (selectedIndex == 0) {
cnt2.visible = false;
cnt1.visible = true;
}
@40
40 / httpQmlJson.qml
Created July 28, 2012 07:37
Simple HTTP JSON Request in QML
import bb.cascades 1.0
Page {
content: Container {
Label {
id: emailLabel
text: qsTr("Email")
}
Label {
id: urlLabel
@40
40 / gist:3240881
Created August 2, 2012 21:38 — forked from tracycodes/gist:3233358
Answer to a random interview question
function add1(array, val, n) {
var iter = 0,
end = array.length,
count = (n) ? n : -1,
multiple = 1;
if(n < 0) {
iter = array.length - 1;
end = 0;
multiple = -1;
@40
40 / tiledBGContainer.qml
Created August 11, 2012 20:46
Applying tiled background to container or page in #BB10 Cascades
Container {
id: rootContainer
background: back.imagePaint
attachedObjects: [
ImagePaintDefinition {
id: back
repeatPattern: RepeatPattern.XY
imageSource: "asset:///container/tiled/core16x16"
}
]