Skip to content

Instantly share code, notes, and snippets.

View ccjeng's full-sized avatar

Andy Cheng ccjeng

  • Taiwan
View GitHub Profile
@ccjeng
ccjeng / TabFragment.java
Created December 28, 2015 02:32
Android TabLayout TabFragment
public class TabFragment extends Fragment {
private static final String ARG_POSITION = "position";
private int position;
public static TabFragment newInstance(int position) {
TabFragment f = new TabFragment();
Bundle b = new Bundle();
b.putInt(ARG_POSITION, position);
@ccjeng
ccjeng / RealmMigration.java
Created April 9, 2016 13:24
Realm backup / restore
public class RealmMigration {
private final static String TAG = RealmMigration.class.getName();
private Context context;
private Realm realm;
public RealmMigration(Context context) {
this.realm = Realm.getInstance(BaseApplication.realmConfiguration);
this.context = context;
@ccjeng
ccjeng / TheBackupAgent-File.java
Created June 22, 2016 04:39
BackupAgent for Android Backup API
public class TheBackupAgent extends BackupAgentHelper {
private static final String DB_NAME = "test.db"; // db name
@Override
public void onCreate() {
FileBackupHelper dbs = new FileBackupHelper(this, DB_NAME);
addHelper("dbs", dbs);
}
@ccjeng
ccjeng / CustomInfoWindowAdapter.java
Last active February 27, 2024 12:40
Custom InfoWindow Layout for Google Map in Android
public class CustomInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
private Activity context;
public CustomInfoWindowAdapter(Activity context){
this.context = context;
}
@Override
@ccjeng
ccjeng / NewTaipeiRecycle.json
Last active August 12, 2018 07:12
新北市黃金資收站設置資訊 / 臺北市垃圾資源回收、廚餘回收限時收受點 / 臺北市週三、週日廚餘專用限時收受點
[{"number":"1","district":"板橋區","village":"中山里","no":"01-001","name":"林爽","address":"板橋區大觀路2段37巷280號","tel":"02-82752345","recycle_address":"板橋區大觀路2段37巷280號","open_time":"每週六早上 06:00--10:00","state":"營運中","twd97X":"295382.67","twd97Y":"2765962.44","wgs84aX":"121.449601129258","wgs84aY":"25.0009896915842"},{"number":"2","district":"板橋區","village":"廣德里","no":"01-002","name":"周建和","address":"板橋區重慶路283號","tel":"02-29643797","recycle_address":"同里辦及新北市板橋區廣德里5鄰重慶路353巷7號對面","open_time":"每週一至日9~12點+15~18點","state":"營運中","twd97X":"296817.42","twd97Y":"2765792.68","wgs84aX":"121.463808943393","wgs84aY":"24.9994134533018"},{"number":"3","district":"板橋區","village":"景星里","no":"01-003","name":"林志成","address":"板橋區景福路11號","tel":"02-29531072","recycle_address":"新北市板橋區景星里3鄰景福路11號","open_time":"每週四 09:00~16:00","state":"營運中","twd97X":"296532.5","twd97Y":"2766464.62","wgs84aX":"121.461009012507","wgs84aY":"25.0054885651095"},{"number":"4","district":"板橋區","village":"滿翠里","no":"01-004","name":"林重光","address":"板橋區四維路266巷5弄16號","tel
import requests
from bs4 import BeautifulSoup
urlRoot = 'http://book.tpml.edu.tw/webpac/'
dateRange = '2016-08-01%2C2016-08-31'
rows = '1000'
link = urlRoot + 'newbooknotftdList.do?sortfield=MarcInsertDate&sorttype=1&showtuple=' + rows + '&newbookdatebet='+ dateRange +'&pubyear=all&language=chi&classtype=all&classno=all&classno10=all&keepsiteid=all&type=&categoraycode=-1&bookstatus=all&collection=all&viewmode=0'
res = requests.get(link)
soup = BeautifulSoup(res.text.encode('utf-8'), 'html.parser')
@ccjeng
ccjeng / PlaceAutoComplete.java
Created September 10, 2016 12:54
Google Places Autocomplete API
private PlaceAutocompleteAdapter adapter;
private AutoCompleteTextView autocompleteView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buildGoogleApiClient();
@ccjeng
ccjeng / deleteRealmIfMigrationNeeded.java
Created September 11, 2016 12:43
deleteRealmIfMigrationNeeded
import android.app.Application;
import io.realm.RealmConfiguration;
public class MyApplication extends Application {
public static RealmConfiguration realmConfiguration;
@Override
public void onCreate() {
super.onCreate();
realmConfiguration = new RealmConfiguration.Builder(this)
@ccjeng
ccjeng / addPerson.java
Created September 11, 2016 12:50
Realm Transaction Block
public void addPerson() {
final Realm realm = Realm.getDefaultInstance();
//It automatically handles begin/commit, and cancel if an error happens
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
Person p = realm.createObject(City.class);
p.setId("00002");
c.setName("Steve Jobs");
@ccjeng
ccjeng / getPersons.java
Last active September 11, 2016 13:27
Realm rxjava sample
public Observable<List<Person>> getPersons() {
final Realm realm = Realm.getDefaultInstance();
return realm.where(Person.class).findAll() //get Persons from DB
.asObservable()
.map(new Func1<RealmResults<Person>, List<Person>>() {
@Override
public List<Person> call(RealmResults<Person> person) {
return realm.copyToRealm(person); //Convert RealmResults to List
}