[JavaScript]Fireworksコマンド - 選択スライスの名前に座標,サイズを付ける

選択スライスの名前に座標,サイズを付ける

var sliceArray = new Array();
for (var i=0;i<fw.selection.length;i++){
	if(fw.selection[i] =="[object SliceHotspot]")sliceArray.push(i);
}

var newName = prompt("input base name", "a_");
for (var i=0;i<sliceArray.length;i++){
	var n = sliceArray[i];
	fw.selection[n].baseName = newName+"_"+fw.selection[n].left+"_"+fw.selection[n].top+"_"+fw.selection[n].width+"_"+fw.selection[n].height;
}

[PHP]配列の値だけの配列を作る

配列の値だけの配列を作る

$data=array();
$data['jack']=array( 'gender'=>'male', 'size'=>198, 'status'=>array('QK',32,'skyhigh','log'=>array('20120303','20120529','20121111') ) );
$data['jeff']=array( 4,87,8,4,3 );
$data['pole']=array( 'address'=>'earth', 'phone number'=>'39028502753' );

echo '<pre>';
var_dump( getValuesByArray($data) );
echo '</pre>';

function getValuesByArray($targetArray){
    if( !is_array($targetArray) ){
        return array($targetArray);
    }
    $tmp=array();
    foreach($targetArray as $key => $value){
        $tmp=array_merge($tmp, getValuesByArray($value) );
    }
    return $tmp;
}

出力結果

array(15) {
  [0]=>
  string(4) "male"
  [1]=>
  int(198)
  [2]=>
  string(2) "QK"
  [3]=>
  int(32)
  [4]=>
  string(7) "skyhigh"
  [5]=>
  string(8) "20120303"
  [6]=>
  string(8) "20120529"
  [7]=>
  string(8) "20121111"
  [8]=>
  int(4)
  [9]=>
  int(87)
  [10]=>
  int(8)
  [11]=>
  int(4)
  [12]=>
  int(3)
  [13]=>
  string(5) "earth"
  [14]=>
  string(11) "39028502753"
}

サンプル

[objective-c]NSDateから文字列生成

NSDateから文字列生成

-(NSString*) getDatetimeFromDate:(NSDate*)date
{
    NSDateFormatter* form = [[NSDateFormatter alloc] init];
    NSCalendar* cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    [form setCalendar: cal];
    [form setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString* str = [form stringFromDate:date];
    return str;
}
NSString*dateString=[self getDatetimeFromDate:[NSDate date]];

[objective-c]EGODatabase #9 カラムの型一覧取得

カラムの型一覧取得

-(EGODatabase*)getDB
{
    EGODatabase* database = [EGODatabase databaseWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/database.db"]];
    return database;
}
-(NSDictionary*)getColumnTypesByTableName:(NSString*)tableName
{
    EGODatabase*db=[self getDB];
    NSString*sql=[NSString stringWithFormat:@"pragma table_info(%@)",tableName];
    EGODatabaseResult*result=[db executeQuery:sql];
    NSMutableDictionary*dic=[NSMutableDictionary dictionary];
    for (EGODatabaseRow*row in result) {
        [dic setObject:[row stringForColumn:@"type"] forKey:[row stringForColumn:@"name"]];
    }
    return dic;
}

[objective-c]EGODatabase #8 カラム名一覧取得

カラム名一覧取得

-(NSArray*)getColumnNamesByTableName:(NSString*)tableName{
    EGODatabase*db=[self getDB];
    NSString*sql=[NSString stringWithFormat:@"pragma table_info(%@)",tableName];
    EGODatabaseResult*result=[db executeQuery:sql];
    NSMutableArray*list=[NSMutableArray arrayWithCapacity:[result count]];
    for (EGODatabaseRow*row in result) {
        [list addObject:[row stringForColumn:@"name"]];
    }
    return [NSArray arrayWithArray:list];
}

[objective-c]EGODatabase #7 テーブル一覧取得

テーブル一覧取得

-(NSArray*)getTableNameList{
    EGODatabase*db=[self getDB];
    NSString*sql=@"select name from sqlite_master where type = 'table' order by name";
    EGODatabaseResult*result=[db executeQuery:sql];
    NSMutableArray*list=[NSMutableArray arrayWithCapacity:[result count]];
    for (EGODatabaseRow*row in result) {
        [list addObject:[row stringForColumn:@"name"]];
    }
    return [NSArray arrayWithArray:list];
}
-(EGODatabase*)getDB{
    EGODatabase* database = [EGODatabase databaseWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/database.db"]];
    return database;
}
-(BOOL)isExistTableByName:(NSString*)tableName{
    NSArray*tables=[self getTableNameList];
    return [tables containsObject:tableName];
}