Skip to content

Instantly share code, notes, and snippets.

View NguyenDa18's full-sized avatar
🎧
Listening to Funny Podcasts

Danh Nguyen NguyenDa18

🎧
Listening to Funny Podcasts
View GitHub Profile
@NguyenDa18
NguyenDa18 / base64_use.py
Created March 10, 2022 23:33
Base64 Encoding/Decoding String with Python
import base64
encoded_string = base64.b64encode(bytes(string, 'utf-8'))
# source: https://stackoverflow.com/questions/21478086/how-to-store-binary-data-in-dynamo-with-boto
email_addreses = [base64.b64decode(item['EmailAddress'].value).decode('utf-8') for item in queried_items]
@NguyenDa18
NguyenDa18 / remove_parens.py
Created March 10, 2022 21:27
Remove parentheses with Python
parens_table = str.maketrans(dict.fromkeys("()"))
# remove parens
converted = converted.translate(parens_table)
return converted
@NguyenDa18
NguyenDa18 / store.ts
Created March 4, 2022 07:05
Redux TS Setup
import { configureStore } from '@reduxjs/toolkit'
export interface AccountState {
readonly isInitialized: boolean
readonly isLoading: boolean
readonly isAuthenticated: boolean
readonly errorMessage?: string
}
/**
@NguyenDa18
NguyenDa18 / functions.py
Last active June 9, 2021 21:47
Python Functions
import re
def batch_data(Items, size):
result = []
i = 0
while (i < len(Items)):
batch = Items[i:i + size]
result.append(batch)
i = i + size
return result
@NguyenDa18
NguyenDa18 / info.md
Last active June 23, 2020 19:12
Portland Tech Jobs Summary
@NguyenDa18
NguyenDa18 / gen-csv.js
Created May 26, 2020 23:52
Generate CSV Download Link From Array
const generateHeader = (header) => {
const newHeader = header.map(key => {
const replacement = headerMappings[key] === undefined ? key : headerMappings[key]
return replacement
})
return newHeader
}
const convertArrayOfObjectsToCSV = arrayOfObjects => {
@NguyenDa18
NguyenDa18 / excel-lambda.js
Created February 27, 2020 19:49
AWS Excel Read + Update DB Lambda
const AWS = require('aws-sdk')
AWS.config.update({
region: "<region>",
});
const s3 = new AWS.S3()
const docClient = new AWS.DynamoDB.DocumentClient();
const xlsx = require('node-xlsx')
const testfilename = "<file>.xlsm"
// src: https://stackoverflow.com/questions/40535757/download-xlsx-from-s3-and-parse-it
@NguyenDa18
NguyenDa18 / reagent.md
Last active January 15, 2020 23:16
Clojure Reagent & Reframe

Reagent Notes

  • Usage [reagent.core :as r]

Syntax Quirks

  • [:<> [*components*]] = JSX Fragment for Reagent
  • [:> *Component*] = shorthand for [(r/adapt-react-class *Component*)]
  • [:> *Component* {:variant "some-prop"} "Click me"] = send JSX element properties as a map
  • (js->clj myobj :keywordize-keys true) = parse JSON to Clojure map (I think)

Quick Example

@NguyenDa18
NguyenDa18 / clojure-quicksheet.md
Created November 19, 2019 19:33
Clojure Quicksheet

Clojure Cheats

  • Get substring after /begin starting string
(str/split uri #"/begin")