Skip to content

Instantly share code, notes, and snippets.

View khangvan's full-sized avatar
🎯
Focusing

Thai Khang Van khangvan

🎯
Focusing
View GitHub Profile
@khangvan
khangvan / python_fetch
Created September 28, 2019 04:47
python_fetch_paco
#!pip install paco
import paco
import aiohttp
async def fetch(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as res:
return res
@khangvan
khangvan / Readme.md
Last active June 9, 2019 08:22 — forked from stekhn/weightedMean.js
Weighted arithmetic mean (average) in JavaScript

Start with code

To do calcaculating weight mean of prvide of array

@khangvan
khangvan / docker-examples.md
Created August 31, 2018 01:47 — forked from thaJeztah/docker-examples.md
Some docker examples

Commit, clone a container

To 'clone' a container, you'll have to make an image of that container first, you can do so by "committing" the container. Docker will (by default) pause all processes running in the container during commit to preserve data-consistency.

For example;

docker commit --message="Snapshot of my container" my_container my_container_snapshot:yymmdd
@khangvan
khangvan / iris-tensorflow-js.js
Created August 24, 2018 05:03 — forked from learncodeacademy/iris-tensorflow-js.js
Solving Iris with Tensorflow.js and Iris JSON dataset
import * as tf from "@tensorflow/tfjs"
import "@tensorflow/tfjs-node"
import iris from "./iris.json"
import irisTesting from "./iris-testing.json"
// convert/setup our data
const trainingData = tf.tensor2d(iris.map(item => [
item.sepal_length, item.sepal_width, item.petal_length, item.petal_width,
]))
const outputData = tf.tensor2d(iris.map(item => [
@khangvan
khangvan / classifytext.R
Last active April 30, 2020 16:45 — forked from primaryobjects/classifytext.R
[Classification R Simple ]Simple example of classifying text in R with machine learning (text-mining library, caret, and bayesian generalized linear model) #R #machinelearning #clasification
library(caret)
library(tm)
# Training data.
data <- c('Cats like to chase mice.', 'Dogs like to eat big bones.')
corpus <- VCorpus(VectorSource(data))
# Create a document term matrix.
tdm <- DocumentTermMatrix(corpus, list(removePunctuation = TRUE, stopwords = TRUE, stemming = TRUE, removeNumbers = TRUE))
@khangvan
khangvan / gist:52b1442fbc36ed004554b3477699ee8e
Created November 14, 2017 04:52 — forked from btsimonh/gist:63e72ded918a5da2d7e5eb057674f4cb
ADVANCED MOTION DETECTION WITH NODE-OPENCV IN NODE-RED flow1
[{"id":"d3a698fb.007c88","type":"inject","z":"fa9050d8.3686","name":"Start","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"x":130,"y":80,"wires":[["47e40795.d58228"]]},{"id":"47e40795.d58228","type":"function","z":"fa9050d8.3686","name":"LoadCV","func":"var require = global.get('require');\n// try for global install\nvar cv = null\ntry{\n cv = require.main.require('opencv');\n} catch(e){\n cv = require('opencv');\n}\nif (cv === null){\n node.warn('node-opencv not found');\n return;\n}\n\nvar cvdesc = Object.keys(cv);\nnode.send([null, {payload:cvdesc}]);\nflow.set('cv', cv);\n\nnode.send({payload:1});\nnode.send({payload:'next'});\n","outputs":"2","noerr":0,"x":260,"y":80,"wires":[["46d283a6.ce321c"],[]]},{"id":"46d283a6.ce321c","type":"function","z":"fa9050d8.3686","name":"GetImage","func":"\n\nif (msg.payload === 0){\n var vid = flow.get('cvvid');\n if (vid){\n node.warn(util.inspect(vid));\n vid.release();\n flow.set('cvvid', null)
@khangvan
khangvan / ipak.R
Created November 7, 2017 07:02 — forked from stevenworthington/ipak.R
Install and load multiple R packages at once
# ipak function: install and load multiple R packages.
# check to see if packages are installed. Install them if they are not, then load them into the R session.
ipak <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}
@khangvan
khangvan / ipak.R
Created November 7, 2017 07:02 — forked from stevenworthington/ipak.R
Install and load multiple R packages at once
# ipak function: install and load multiple R packages.
# check to see if packages are installed. Install them if they are not, then load them into the R session.
ipak <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}
@khangvan
khangvan / ajax.js
Created September 29, 2017 11:31 — forked from xeoncross/ajax.js
Simple, cross-browser Javascript POST/GET xhr request object. Supports request data and proper AJAX headers.
/**
* IE 5.5+, Firefox, Opera, Chrome, Safari XHR object
*
* @param string url
* @param object callback
* @param mixed data
* @param null x
*/
function ajax(url, callback, data, x) {
try {
@khangvan
khangvan / Cisco_Anyconnect.ps1
Created July 8, 2017 22:35 — forked from jhorsman/Cisco_Anyconnect.ps1
PowerShell to automate VPN connection with Cisco AnyConnect Secure Mobility Client
#Source www.cze.cz
#This script is tested with "Cisco AnyConnect Secure Mobility Client version 3.1.00495"
# Usage: & '.\Cisco_Anyconnect.ps1' [-Server <server name or ip>] [-Group <group>] [-User <user>] [-Password <password>]
#Please change following variables
#IP address or host name of cisco vpn, Username, Group and Password as parameters
param (
[string]$Server = $( Read-Host "Input server, please" ),