Skip to content

Instantly share code, notes, and snippets.

Avatar
🐌
Back to normal

Tung Dao tungd

🐌
Back to normal
View GitHub Profile
@tungd
tungd / build.gradle.kts
Last active Feb 12, 2019
Configuration file for microservice using Gradle, Spring Boot, Spring Cloud, Spring Webflux, Srping Data JPA, OpenJPA (for entity class generation)
View build.gradle.kts
group = "com.tungdao.sample"
extra["spring.version"] = "5.1.3.RELEASE"
extra["spring.boot.version"] = "2.1.1.RELEASE"
extra["spring.cloud.version"] = "Greenwich.RC2"
plugins {
java
idea
id("org.springframework.boot") version "2.1.1.RELEASE"
@tungd
tungd / index.js
Last active Nov 1, 2018
Sequelize insert demo
View index.js
const Sequelize = require('sequelize')
const sequelize = new Sequelize({
dialect: 'sqlite',
storage: 'db.sqlite3'
})
const Product = sequelize.define('product', {
name: Sequelize.STRING
})
View index.js
const xlsx = require('xlsx')
const table = xlsx.readFile('sample.xlsx', { cellStyles: true })
const sheet = table.Sheets[table.SheetNames[0]];
console.log(sheet)
// sheet['C10'] = { t: 's', v: 'Test update value' }
const addCell = (sheet, cell, value) => {
sheet[cell] = Object.assign({}, sheet[cell], value)
View answers.py
from functools import reduce
# count
reduce(lambda i, _: i + 1, [1, 2, 3, 4, 5, 6, 2, 3], 0)
# max
reduce(lambda a, b: a if a > b else b, [1, 2, 3, 4, 5, 6, 2, 3])
# min
reduce(lambda a, b: a if a < b else b, [1, 2, 3, 4, 5, 6, 2, 3])
@tungd
tungd / RaiseFund.sol
Last active Aug 1, 2018
Example fund raising contract
View RaiseFund.sol
contract RaiseFund {
address public owner;
uint public target;
uint public total;
bool public ended;
struct Donation {
@tungd
tungd / Example.hs
Created Jul 24, 2018
Example using database pool with `ReaderT`
View Example.hs
#!/usr/bin/env stack
-- stack --resolver lts-12.0 --install-ghc runghc --package mtl --package resource-pool --package mysql-simple
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
import Control.Monad.Reader
import Data.Pool
import Database.MySQL.Simple
@tungd
tungd / RactiveComponentPlugin.js
Created Jul 14, 2018
FuseBox RactiveComponentPlugin (WIP)
View RactiveComponentPlugin.js
const Ractive = require('ractive')
const rcu = require('rcu')
const typescript = require('typescript')
rcu.init(Ractive)
class RactivePlugin {
constructor(options) {
View Servant+Selda.hs
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Servant.Selda where
import Data.Pool
import Database.Selda
import Database.Selda.Backend
import Database.Selda.PostgreSQL (pgOpen')
import RIO
import Servant
@tungd
tungd / parser.py
Created Dec 5, 2017
Parser combinator to skip error.
View parser.py
from parsy import Parser, Result
class Text(object):
'''Structure to contain all the parts that the parser does not understand.
A better name would be Whitespace
'''
def __init__(self, text=''):
self.text = text
@tungd
tungd / TemplageEngineTest.hs
Created Nov 17, 2017
Template Engine Test in Haskell. So far: Lucid is 10x faster than Mustache, and is 200x faster than EDE
View TemplageEngineTest.hs
#!/usr/bin/env stack
-- stack --resolver lts-9.13 --install-ghc runghc --package scotty
-- --package wai --package wai-middleware-prometheus --package warp --package text --package unix
-- --package lucid --package ede --package mustache
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Monad.IO.Class
import Data.HashMap.Strict (fromList)