Skip to content

Instantly share code, notes, and snippets.

@pec1985
pec1985 / main.cpp
Created February 21, 2015 00:16
Usage of std::mutex
#include <thread>
#include <memory>
#include <mutex>
#include <iostream>
#include <vector>
#define USE_MUTEX 1
class Foo
@pec1985
pec1985 / app.js
Last active January 30, 2018 14:58
Array indexOf vs for loop
function Pe(){};
var len = 1000000;
var half = len / 2;
var array = [];
var last = new Pe();
while(len--) {
array.push(new Pe());
}
array.push(last);
@pec1985
pec1985 / app.js
Created September 23, 2014 00:31
Events on buttons
var win = Ti.UI.createWindow();
var btn = Ti.UI.createButton({
title: 'click me'
});
win.add(btn);
win.open();
btn.addEventListener('click', function () {
Ti.API.info('First "click" event on the button fired!');
});
@pec1985
pec1985 / ti.error.view.m
Last active August 29, 2015 13:56
Playing around with autolayout in iOS
- (void)loadView
{
self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
UIView *view = [[UIView alloc] init];
view.backgroundColor = [UIColor redColor];
[view setBackgroundColor:[UIColor redColor]];
[self setView:view];
UIButton *dismissButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
@pec1985
pec1985 / listview_index_column.js
Last active December 28, 2015 01:28
Index column in the listview
/* Ever wondered how to get the nice column of letters in the right side
* of the list view?
*
* Here is an example:
* 1. We take a list of names from a json file
* 2. We need to sort them by either first name or last name
* 3. We need to create a row header once in a while, when the first letter changes
* 4. We need to create a table index
*
*/
@pec1985
pec1985 / RHelper.java
Created June 24, 2013 03:54
Helper to get R. in Titanium Android
package com.pec1985.tigolf;
import org.appcelerator.titanium.util.TiRHelper;
import org.appcelerator.titanium.util.TiRHelper.ResourceNotFoundException;
public class RHelper {
public static int getString(String str){
try {
return TiRHelper.getApplicationResource("string."+str);
@pec1985
pec1985 / app.js
Created May 16, 2013 17:17
Simple script to create a lot of ACS Users with Titanium
var json = {"HasMore":false,"FuelStations":[{"StationId":"POIID-2011Q1_32035298","FuelPrice":[{"FuelType":1,"CapacityPrice":{"Value":4.139,"Units":"GAL","Currency":"USD"},"PriceTimestampLocal":"2013-05-10T12:17:00.000+0000","PriceTimestampGMT":"2013-05-10T19:17:34.000+0000"},{"FuelType":4,"CapacityPrice":{"Value":4.259,"Units":"GAL","Currency":"USD"},"PriceTimestampLocal":"2013-05-13T17:03:00.000+0000","PriceTimestampGMT":"2013-05-14T00:03:30.000+0000"},{"FuelType":3,"CapacityPrice":{"Value":4.159,"Units":"GAL","Currency":"USD"},"PriceTimestampLocal":"2013-05-13T17:03:00.000+0000","PriceTimestampGMT":"2013-05-14T00:03:30.000+0000"},{"FuelType":2,"CapacityPrice":{"Value":4.099,"Units":"GAL","Currency":"USD"},"PriceTimestampLocal":"2013-05-14T14:25:00.000+0000","PriceTimestampGMT":"2013-05-14T21:25:45.000+0000"}],"Brand":"76","LastUpdateTimestamp":"2013-05-16T04:06:26.000+0000","Routing":{"href":"http://fuel.si.public.devbln.europe.nokia.com/1.0/routing/calculateroute?waypoint=37.332332611083984,-122.0312194824
@pec1985
pec1985 / app.js
Created May 10, 2013 17:09
Double Slider
var Slider = require('slider');
var win = Ti.UI.createWindow();
var slider = Slider({
left: 10,
right: 10,
height: 40
});
@pec1985
pec1985 / TiUIScrollViewProxy+Extended.h
Created May 5, 2013 02:25
Extension to TiUIScrollView to get content size
//
// TiUIScrollViewProxy+Extended.h
// TiGoodies
//
// Created by Pedro Enrique on 4/8/13.
//
//
#define USE_TI_UISCROLLVIEW
#import "TiUIScrollViewProxy.h"
@pec1985
pec1985 / dd.js
Last active December 16, 2015 15:09
BlackBerry generate setters
// Sample setters
var setters = [
'currentPage'
, 'disableBounce'
, 'overScrollMode'
, 'overlayEnabled'
, 'pagingControlAlpha'
, 'pagingControlColor'
, 'pagingControlHeight'