Skip to content

Instantly share code, notes, and snippets.

View martinyung's full-sized avatar

Martin martinyung

View GitHub Profile

Keybase proof

I hereby claim:

  • I am martinyung on github.
  • I am m4rt1nk (https://keybase.io/m4rt1nk) on keybase.
  • I have a public key ASCLKU6hw67b1T8swA9xcKSZerz1Ynk86lH1xT2TftchrAo

To claim this, I am signing this object:

@martinyung
martinyung / main.py
Last active January 29, 2022 14:10
python etl
def main():
print('starting etl')
# establish connection for target database (sql-server)
target_cnx = pyodbc.connect(**datawarehouse_db_config)
# loop through credentials
# mysql
for config in mysql_db_config:
@martinyung
martinyung / sql_queries.py
Last active January 29, 2022 14:11
python etl
# example queries, will be different across different db platform
firebird_extract = ('''
SELECT fbd_column_1, fbd_column_2, fbd_column_3
FROM fbd_table;
''')
firebird_insert = ('''
INSERT INTO table (column_1, column_2, column_3)
VALUES (?, ?, ?)
''')
@martinyung
martinyung / etl.py
Last active January 29, 2022 14:11
python etl
def etl(query, source_cnx, target_cnx):
# extract data from source db
source_cursor = source_cnx.cursor()
source_cursor.execute(query.extract_query)
data = source_cursor.fetchall()
source_cursor.close()
# load data into warehouse db
if data:
target_cursor = target_cnx.cursor()
@martinyung
martinyung / db_credentials.py
Last active January 29, 2022 14:11
python etl
from variables import datawarehouse_name
# sql-server (target db, datawarehouse)
datawarehouse_db_config = {
'Trusted_Connection': 'yes',
'driver': '{SQL Server}',
'server': 'datawarehouse_sql_server',
'database': '{}'.format(datawarehouse_name),
'user': 'your_db_username',
'password': 'your_db_password',
@martinyung
martinyung / UploadController.groovy
Last active September 9, 2017 05:41
[blogging purpose] grails upload controller
package [Your_Project]
class UploadController {
def amazonS3Service
def s3Bucket = 'Your_S3_Bucket_Name'
def index() {
def uploadedFile = request.getFile('file')
@martinyung
martinyung / Upload.vue
Last active September 9, 2017 05:28
[blogging purpose] file upload vuejs component - js
<script>
const BASE_URL = "[YOUR_PROJECT_URL]"
export default {
name: 'FileUpload',
directives: {
uploader: {
bind (el, binding, vnode) {
el.addEventListener('change', e => {
@martinyung
martinyung / Upload.vue
Created September 9, 2017 05:04
[blogging purpose] file upload vuejs component - template
<!-- HTML Template -->
<template>
<div>
<div class="input-group">
<input type="text" class="form-control" placeholder="Select file..." :value="file.name" readonly>
<span class="input-group-btn">
<button class="btn btn-default" type="button" @click="selectFile">Select file</button>
<button class="btn btn-default" type="button" @click="uploadFile">Upload</button>
</span>
</div>
@martinyung
martinyung / hello.jsx
Last active June 25, 2017 08:07
conversational-form with react.js - render()
class Hello extends Component {
...
render() {
return (
<div>
<h2>Conversational Form</h2>
<div id="cf-context" > {/* <-- the cf form will be bound to this element */}
<form id="form" className="form" ref="form">
<input type="text" ref="name" placeholder="Name" defaultValue={this.props.name}/>
@martinyung
martinyung / hello.jsx
Last active June 25, 2017 08:07
conversational-form with react.js - add cf info
class Hello extends Component {
...
componentDidMount(){
// customize your questions here
this.refs.name.setAttribute('cf-questions', "What is your name?");
this.refs.email.setAttribute('cf-questions', "What is your email?");
this.refs.description.setAttribute('cf-questions', "Describe your requirement");
this.cf = window.cf.ConversationalForm.startTheConversation({