Skip to content

Instantly share code, notes, and snippets.

View pbdanny's full-sized avatar

Danny Thanakrit Boonquarmdee pbdanny

  • Bangkok, Thailand
View GitHub Profile
@pbdanny
pbdanny / RL Credit Limit.R
Created October 20, 2017 10:33
RL Credit Limit
library(RODBC)
con <- odbcConnectAccess2007("D:/Backup/OSS & TS - Performance/OSSDatabase.accdb")
# sqlTables(con)
topQuery <- "select top 10 *
from qry_RL_Portfolio_M
where Month between '201701' and '201709'
and Result = 'A';"
@pbdanny
pbdanny / convertExcelSheet.gs
Created August 18, 2017 12:15
Google Script Convert Excel to Google Sheet
var uploadFile = JSON.parse(UrlFetchApp.fetch(
"https://www.googleapis.com/upload/drive/v2/files?uploadType=media&convert=true",
{
method: "POST",
contentType: file.getMimeType(),
payload: file.getBlob().getBytes(),
headers: {
"Authorization" : "Bearer " + ScriptApp.getOAuthToken()
},
muteHttpExceptions: true
@pbdanny
pbdanny / MSAccessPandas_Access.py
Created July 7, 2017 10:33
Use pandas_access to connect to MS Access. (Needed 'mdbtools' installed)
import pandas_access as mdb
# show tables in databases
for tbl in mdb.list_tables('/Users/Danny/Share Win7/2017OSSDatabase.accdb'):
print(tbl)
# Read in table as pandas dataframe
# Limited capability to small tables
df = mdb.read_table('/Users/Danny/Share Win7/2017OSSDatabase.accdb', 'Region_KTC')
@pbdanny
pbdanny / MSAccessJayDeBeAPI.py
Created July 7, 2017 10:30
Use JayDeBeAPI with JDBC connect to MS Access
import jaydebeapi
# Initiate Java runtiome file location
ucanaccess_jars = [
"/Users/Danny/Documents/UCanAccess-4.0.2-bin/ucanaccess-4.0.2.jar",
"/Users/Danny/Documents/UCanAccess-4.0.2-bin/lib/commons-lang-2.6.jar",
"/Users/Danny/Documents/UCanAccess-4.0.2-bin/lib/commons-logging-1.1.1.jar",
"/Users/Danny/Documents/UCanAccess-4.0.2-bin/lib/hsqldb.jar",
"/Users/Danny/Documents/UCanAccess-4.0.2-bin/lib/jackcess-2.1.6.jar",
@pbdanny
pbdanny / connectMSAccess.py
Created June 30, 2017 11:17
Python connect MS Access
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 30 15:33:09 2017
@author: Thanakrit.B
"""
import pyodbc
# Check if MS Access driver availabel
@pbdanny
pbdanny / date_time-in-R.R
Last active December 3, 2022 15:08
Date - Time in R
# Date data in Excel stored in format no. of day from origin (1899-12-30)
# While POSIXct use format no. of second from origin
# Then convert form #day -> #second
textWinDateConv2 <- function (d) {
t <- as.POSIXct(as.numeric(d) * 60*60*24 , # Convert days to second for POSIXct time scales
# Set origin to Bankok minus 17 min 56 sec for correct timezone origin before 1920
# https://en.wikipedia.org/wiki/Time_in_Thailand
origin = (as.POSIXct("1899-12-30", tz = "Asia/Bangkok") - (17*60+56)),
tz = "Asia/Bangkok") # To assure out put time zone
@pbdanny
pbdanny / plotly-docs.R
Created December 31, 2016 12:56 — forked from cpsievert/plotly-docs.R
Plotly examples
# install the new/experimental plotly R package
# devtools::install_github("ropensci/plotly@carson-dsl")
# ----------------------------------------------------------------------
# https://plot.ly/r/3d-line-plots/
# ----------------------------------------------------------------------
library(plotly)
# initiate a 100 x 3 matrix filled with zeros