Skip to content

Instantly share code, notes, and snippets.

View cherihung's full-sized avatar

Cheri Hung cherihung

View GitHub Profile
@cherihung
cherihung / csv-to-mkdown-files.py
Last active April 20, 2022 06:32
convert each row in csv to a markdown file in python
import csv
def toMarkdown(item):
newTemp = "---"+"\n"+"layout: sculpture"+"\n"+"pageId: "+item[0]+"\n"+"uid: "+item[1]+"\n"
newTemp += "title: "+item[2]+"\n"+"location: "+item[3]+"\n"+"completionDate: "+item[4]+"\n"
newTemp += "description: "+item[5]+"\n"+"imageId: "+item[6]+"\n"
newTemp += "---"+"\n"
return newTemp
with open('file.csv', 'rb') as f:
let cache;
const TTL = 1500;
const callApi = () => {
return new Promise((res, rej) => res('1234'))
}
async function getData() {
if (cache) return cache;
try {
const newProm = await callApi();
console.log('get new result', newProm);
@cherihung
cherihung / allSettled.js
Created February 20, 2022 00:25
allSettled implementations
async function success() {
return new Promise((res, rej) => res('Resolved'));
}
async function error() {
return new Promise((res, rej) => rej('Rejected'));
}
// then, catch syntax
function allSettled(promises) {
const allPromises = promises.map((p) => {
@cherihung
cherihung / wp-prevnext.php
Created August 4, 2013 23:23
create prev/next nav for custom post type. something that works like this plugin http://wordpress.org/plugins/previous-and-next-post-in-same-taxonomy/ but can offer order by menu order
//from this post http://bucketpress.com/next-and-previous-post-link-in-same-custom-taxonomy
// get_posts in same custom taxonomy
$postlist_args = array(
'posts_per_page' => -1,
'orderby' => 'menu_order title',
'order' => 'ASC',
'post_type' => 'your_custom_post_type',
'your_custom_taxonomy' => 'your_custom_taxonomy_term'
);
$postlist = get_posts( $postlist_args );
@cherihung
cherihung / createLargeFile.js
Created March 21, 2021 23:30
generate any large file
const fs = require('fs');
const path = require('path');
const bytes_100 = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mauris augue, vulputate sit amet dolor.\n';
const bytes_400 = bytes_100.repeat(4)
const fileName = 'file.txt';
const file = fs.createWriteStream(path.join(__dirname, fileName));
for (let i = 0; i <= 1e6; i++) {
file.write(bytes_400);
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
"github.com/gin-gonic/gin"
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
"github.com/cherihung/go-server-starter/config"
package config
import (
"fmt"
"path"
"github.com/spf13/viper"
)
var appConfigs AppConfiguration
# 1 choose a compiler OS
FROM golang:alpine AS builder
# 2 (optional) label the compiler image
LABEL stage=builder
# 3 (optional) install any compiler-only dependencies
RUN apk add --no-cache gcc libc-dev
WORKDIR /workspace
# 4 copy all the source files
COPY . .
# 5 build the GO program
const compose = (...functions) => x => functions.reduce((acc, fn) => fn(acc), x);
// compose(fn1, fn2, fn3)
const pipe = functions => data => {
return functions.reduce(
(value, func) => func(value),
data
);
};