Skip to content

Instantly share code, notes, and snippets.

View huygn's full-sized avatar

Huy Giang huygn

View GitHub Profile
@huygn
huygn / 1.ngx-reactify.tsx
Created October 6, 2023 06:37 — forked from lacolaco/1.ngx-reactify.tsx
A React component to render a standalone Angular component (Angular v14.2 is required)
import { ApplicationRef, ComponentRef, createComponent, Type } from "@angular/core";
import { createApplication } from "@angular/platform-browser";
import React, { useEffect, useRef, useState } from "react";
type AnyComponentRef = ComponentRef<unknown>;
export type ReactifyProps = {
component: Type<unknown>;
inputs?: Record<string, unknown>;
};
function mergeUint8Arrays(...arr: Uint8Array[]) {
const size = arr.reduce((acc, v) => acc + v.byteLength, 0);
let merged = new Uint8Array(size);
let offset = 0;
for (const u of arr) {
merged.set(u, offset);
offset += u.byteLength;
}
return merged;
}
@huygn
huygn / useHotkeys.ts
Created April 26, 2019 04:15 — forked from pedronauck/useHotkeys.ts
usePopper and useHotkeys hooks
import { useEffect } from 'react'
import hotkeys from 'hotkeys-js'
export const useHotkeys = (key: string, cb: () => any, inputs?: any[]) => {
useEffect(() => {
hotkeys(key, cb)
return () => hotkeys.unbind(key)
}, inputs)
}
@huygn
huygn / spacemacs-shorcuts.md
Last active October 7, 2018 10:44 — forked from robphoenix/spacemacs-cheshe.md
Spacemacs Cheat Sheet

Useful Spacemacs commands

  • SPC q q - quit
  • SPC w / - split window vertically
  • SPC w - - split window horizontally
  • SPC 1 - switch to window 1
  • SPC 2 - switch to window 2
  • SPC w d - delete current window
  • SPC TAB - switch to previous buffer
  • SPC b b - switch buffers
@huygn
huygn / 00_destructuring.md
Created September 27, 2018 18:10 — forked from john2x/00_destructuring.md
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors

@huygn
huygn / promises-passing-values.cljs
Created September 27, 2018 09:01 — forked from pesterhazy/promises-passing-values.cljs
Promise chains in ClojureScript and the problem of previous values
(ns my.promises
"Demo to show different approaches to handling promise chains in ClojureScript
In particular, this file investigates how to pass data between Promise
callbacks in a chain.
See Axel Rauschmayer's post
http://2ality.com/2017/08/promise-callback-data-flow.html for a problem
statement.
const createLogger = (backgroundColor, color) => {
const logger = (message, ...args) => {
if (logger.enabled === false) {
return;
}
console.groupCollapsed(
`%c${message}`,
`background-color: ${backgroundColor}; color: ${color}; padding: 2px 4px;`,
...args
@huygn
huygn / api.tf
Created July 6, 2018 09:09 — forked from keeth/api.tf
Apex + Terraform + AWS Lambda + API Gateway + JSON Encoded Errors + CORS
resource "aws_api_gateway_rest_api" "myApi" {
name = "myApi-${var.env}"
description = "My awesome API (${var.env} environment)"
}
resource "aws_api_gateway_deployment" "myApi" {
depends_on = [
"aws_api_gateway_integration.myApi_myEndpoint_post",
"aws_api_gateway_integration_response.myApi_myEndpoint_post",
"aws_api_gateway_integration_response.myApi_myEndpoint_post_400",
// Template for slack chat msg
def slackBaseMsg = "*${env.JOB_NAME}* <${env.BUILD_URL}|#${env.BUILD_NUMBER}>"
// Base Predix/tmca repo
def projectName = 'ge-pae'
def tmcaBranch = 'develop'
// List of apps
def apps = ['predix-fm-integration']
// AWS uri
@huygn
huygn / test-runner.js
Created October 30, 2017 06:11
Automation test runner in poi.js app with puppeteer
const path = require('path')
const connect = require('connect')
const superstatic = require('superstatic')
const puppeteer = require('puppeteer')
const poi = require('poi')
const poiConfig = require('../../poi.config')
const rootDir = path.join(__dirname, '../..')
const poiApp = poi({