Skip to content

Instantly share code, notes, and snippets.

View nnguyen168's full-sized avatar

Nam Nguyen nnguyen168

  • France
View GitHub Profile
@nnguyen168
nnguyen168 / airflow_example.py
Last active June 19, 2020 07:09
An example of job scheduling in Apache Airflow
# import libraries
from datetime import datetime, timedelta
from airflow import DAG
from airflow.operators.python_operator import PythonOperator
from airflow.operators.bash_operator import BashOperator
# the default parameters for each operation/task
default_args = {
'owner': 'big_data_guy',
'depends_on_past': False,
@nnguyen168
nnguyen168 / function_without_procastination.py
Created May 24, 2020 08:08
Function without procastination
def sum_of_two_numbers(first_number, second_number):
return first_number + second_number
@nnguyen168
nnguyen168 / function_with_procastination.py
Created May 24, 2020 08:07
Function with procastination
def sum_of_two_numbers(a, b):
"""
The function to calculates the sum of two numbers
Parameters:
a: integer -> the first number
b: integer -> the second number
Return:
sum: integer -> the result which is the sum of a and b
@nnguyen168
nnguyen168 / to_do_comment.py
Created May 24, 2020 07:50
TO DO comments
# TODO: add a fix later on. The use of this value is temporary
system_stability_rate = 0.4581345
@nnguyen168
nnguyen168 / code_without_redudant_comments.py
Last active May 24, 2020 07:38
Code without redundant comments
def calculate_pay(hourly_pay_rate, work_hours,
overtime_pay_rate, overtime_work_hours,
is_eligible_overtime_rate):
total_pay = 0
totay_pay = hourly_pay_rate * work_hours
if is_eligible_overtime_rate:
total_pay = total_pay + overtime_pay_rate * overtime_work_hours
else:
total_pay = total_pay + hourly_pay_rate * overtime_work_hours
return total_pay
@nnguyen168
nnguyen168 / code_with_redundant_comments.py
Last active May 24, 2020 09:09
Code with redundant comments
def calculate_pay(r, h, ovt, ovh, e):
"""
Function to calculate pay of a specific employee
Parameters:
r: the hourly pay rate
h: the work hours
ovt: the overtime pay rate
ovh: the overtime work hours
e: indicate if employee is eligible for overtime pay
Return:
@nnguyen168
nnguyen168 / jack_analytics_example.json
Last active May 14, 2020 08:16
Jack's analytics example data
{
"visitorId": 1,
"visitTimestamp": 1734239123,
"utcDay": "2020-04-01T15:24:25Z",
"siteActivities": {
"pageViews": 2,
"buttonClicks": 1,
"newVisit": true,
"timeOnScreen": 12
},
@nnguyen168
nnguyen168 / john_analytics_example
Last active May 14, 2020 08:06
John's analytics example data
{
"visitorId": "1",
"visitId": "1501583974",
"visitStartTime": "1501583974",
"date": "20170801",
"totals": {
"visits": "1",
"pageviews": "1",
"timeOnSite": null, // -> a lot of NULL values
"bounces": "1",
@nnguyen168
nnguyen168 / address_book.proto
Created May 7, 2020 17:47
Protobuf equivalent of address book model
// source code reference: https://developers.google.com/protocol-buffers/docs/javatutorial
syntax = "proto2";
package tutorial;
option java_package = "com.example.tutorial";
option java_outer_classname = "AddressBookProtos";
message Person {
required string name = 1;
@nnguyen168
nnguyen168 / address_book.json
Created May 7, 2020 17:04
JSON example to model an address book
{
"people": [
{
"name": "John Doe",
"id": 1,
"email": "john.doe@gmail.com",
"phoneType": "Mobile",
"phoneNumbers": [
{
"number": "1-541-754-3010",