Skip to content

Instantly share code, notes, and snippets.

View peerax's full-sized avatar

peerathai puapan peerax

View GitHub Profile
@peerax
peerax / conCSVtoSQlite.py
Created August 26, 2014 07:35
python import txt,csv to sqlite
import csv, sqlite3
conn = sqlite3.connect("converting2.sqlite")
curs = conn.cursor()
curs.execute("CREATE TABLE document (col1 TEXT, col2 TEXT, col3 TEXT, col4 TEXT,col5 TEXT);")
reader = csv.reader(open('Calendar.txt', 'rU'), delimiter=' ')
for row in reader:
to_db = [unicode(row[0], "utf8"), unicode(row[1], "utf8"), unicode(row[2], "utf8"), unicode(row[3], "utf8"), unicode(row[4], "utf8")]
curs.execute("INSERT INTO document VALUES (?, ?, ?,?,?);", to_db)
conn.commit()
@peerax
peerax / dht.py
Created August 27, 2014 09:56
DHT11,22,2302 in python from https://github.com/adafruit
import sys
import dhtreader
DHT11 = 11
DHT22 = 22
AM2302 = 22
dhtreader.init()
@peerax
peerax / NSUrlSession POST
Created August 28, 2014 09:03
NSUrlsession use POST
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@:%@/getAllUser",[GlobalVar serverIp],[GlobalVar serverPort]]]];
NSDictionary *requestData = [[NSDictionary alloc] initWithObjectsAndKeys:
[defu objectForKey:@"ComId"], @"id",
nil];
NSError *error;
NSData *postData = [NSJSONSerialization dataWithJSONObject:requestData options:0 error:&error];
//Register Notification ในviewDidLoad
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(ชื่อฟังค์ชั่น) name:@"ชื่อโนติ" object:nil];
//Call Notification main thread
[[NSNotificationCenter defaultCenter]postNotificationName:@"ชื่อโนติ" object:self];
@peerax
peerax / gist:b2d191f1be5e20fd875a
Created September 9, 2014 15:21
arduino gsm gprs code
http://stackoverflow.com/questions/8500698/use-arduino-gsm-gprs-shield-to-send-data-to-my-web-service
//
// AppDelegate.swift
// pushtest
//
// Created by sawapi on 2014/06/08.
// Copyright (c) 2014年 sawapi. All rights reserved.
//
// iOS8用
import UIKit
@peerax
peerax / APNSTest.rb
Last active August 29, 2015 14:13 — forked from vzqwer/APNSTest.rb
# Install APNS gem:
# sudo gem install APNS
require 'APNS'
# gateway.sandbox.push.apple.com is default
# APNS.host = 'gateway.push.apple.com' # Production
APNS.host = 'gateway.sandbox.push.apple.com' # Development
# this is also the default. Shouldn't ever have to set this, but just in case Apple goes crazy, you can.
APNS.port = 2195
@peerax
peerax / add
Created January 26, 2015 08:54
Add UIBarbutton
UIBarButtonItem *btn =[[UIBarButtonItem alloc] initWithTitle:@"Check out" style:UIBarButtonItemStyleBordered target:self action:@selector(Checkout)];
self.navigationItem.rightBarButtonItem = btn;
@peerax
peerax / HTTPpost.java
Created January 30, 2015 06:55
Android Request HTTP class
import android.os.Handler;
import android.os.Message;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
@peerax
peerax / animation.m
Created January 30, 2015 09:57
ios custom transition
- (void)perform {
UIViewController *sourceViewController = self.sourceViewController;
UIViewController *destinationViewController = self.destinationViewController;
// Add the destination view as a subview, temporarily
[sourceViewController.view addSubview:destinationViewController.view];
// Transformation start scale
destinationViewController.view.transform = CGAffineTransformMakeScale(0.05, 0.05);