Skip to content

Instantly share code, notes, and snippets.

View hacksoldier's full-sized avatar

Marco Velluto hacksoldier

  • Milan, Italy
View GitHub Profile
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="lib" path="/Users/Marco/Dropbox/Hackthlon/Libreria per tornare coordinate/Libreria fai da te/JCoord.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
@hacksoldier
hacksoldier / [DATABASE] File Path
Last active December 28, 2015 18:19
[DATABASE] File Path
- (NSString *) filePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
return [documentsDir stringByAppendingPathComponent:@"database.sql"];
}
@hacksoldier
hacksoldier / [DATABASE] Open DB
Last active December 28, 2015 18:19
[DATABASE] Open DB
- (void) openDB {
//-- Create Database --
if (sqlite3_open([[self filePath] UTF8String], &(db)) != SQLITE_OK) {
sqlite3_close(db);
WITH_LOG ? NSLog(@"Database falied to open.") : nil;
}
}
@hacksoldier
hacksoldier / [DATABASE] Create Table
Created November 19, 2013 09:33
[DATABASE] Create Table
- (void)createTableNamed:(NSString *)tableName{
char *err;
NSString *sql = [NSString stringWithFormat:@"CREATE TABLE IF NOT EXISTS '%@' ('%@' "
"INTEGER PRIMARY KEY, '%@' REAL, '%@' REAL);", tableName, @"id", FIELD_WEIGHT , FIELD_DATE];
if (sqlite3_exec(db, [sql UTF8String], NULL, NULL, &err) != SQLITE_OK) {
sqlite3_close(db);
NSLog(@"Table %@ falied create.", tableName);
@hacksoldier
hacksoldier / [DATABASE] Insert New Record
Created November 19, 2013 09:34
[DATABASE] Insert New Record
- (void) insertRecordWithWeight:(float)weight date:(double)date {
int countOfDb = 0;
countOfDb = [self countOfDb];
NSString *sql = [NSString stringWithFormat:@"INSERT OR REPLACE INTO '%@' ('%@','%@','%@')"
"VALUES ('%d','%f','%f')", TABLE_NAME, @"id",FIELD_WEIGHT, FIELD_DATE, countOfDb, weight, date];
char *err;
if (sqlite3_exec(db, [sql UTF8String], NULL, NULL, &err) != SQLITE_OK) {
@hacksoldier
hacksoldier / [Database] Get All
Created November 19, 2013 09:36
[DATABASE] Get all information
- (NSArray *)getAll{
NSString * qsql = [NSString stringWithFormat:@"SELECT * FROM '%@'", TABLE_NAME];
sqlite3_stmt *statment;
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
if (sqlite3_prepare_v2(db, [qsql UTF8String], -1, &statment, nil) == SQLITE_OK) {
while (sqlite3_step(statment) == SQLITE_ROW) {
@hacksoldier
hacksoldier / [PLIST] Read Data From Plist
Created November 26, 2013 20:32
[PLIST] Read Data From Plist
+ (NSDictionary *)getDictionaryArticoliFromPlistName:(NSString *)plistName {
NSString *path = [[NSBundle mainBundle] pathForResource:plistName ofType:@"plist"];
NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:path];
return dictionary;
}
@hacksoldier
hacksoldier / [PLIST] Write dictionary on Plist
Created November 26, 2013 20:33
[PLIST] Write dictionary on Plist
+ (void)writeDictionary:(NSDictionary *)dictionary fromPlistName:(NSString *)plistName {
NSString *path = [[NSBundle mainBundle] pathForResource:plistName ofType:@"plist"];
[dictionary writeToFile:path atomically:YES];
}
@hacksoldier
hacksoldier / Get a list of country names
Created November 28, 2013 21:22
Get a list of country names
NSArray *codes = [[NSArray alloc] initWithArray:[NSLocale ISOCountryCodes]];
@hacksoldier
hacksoldier / Prepare For Segue
Created November 28, 2013 22:13
Prepare For Segue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
[[segue destinationViewController] setDetailItem:object];
}
}