Skip to content

Instantly share code, notes, and snippets.

View vietvudanh's full-sized avatar

Viet Vu vietvudanh

  • Ha Noi, Vietnam
View GitHub Profile
@vietvudanh
vietvudanh / file.go
Last active December 3, 2019 13:30
GO file operations
// read file by line
file, err := os.Open("file.txt")
if err != nil {
log.Fatal(err)
}
defer file.Close()
scan := bufio.NewScanner(file)
for scan.Scan() {
line := scan.Text()
@vietvudanh
vietvudanh / fast_finger.py
Last active November 30, 2019 09:43
Auto 10fastFinger
"""just for fun on 10 fast fin
including some random stuff and error to make it more 'human'
"""
import time
import random
from selenium.webdriver import Chrome, ChromeOptions
WPM = 300
base_interrval = 60 / WPM / 50 # words length + made up for time.sleep(), this should do it
@vietvudanh
vietvudanh / es_commands.js
Last active November 30, 2019 09:44
Elasticsearch Commands
# metadata
GET _cat/indices?
# m, d,i
GET _cat/nodes?V&s=ip:asc
GET _cat/master?v
GET _cat/shards?v
GET _cat/allocations?v
GET _cluster/heatlh
@vietvudanh
vietvudanh / createDataFrame.scala
Last active April 7, 2020 04:15
Spark Dataframe
import org.apache.spark.mllib.random.RandomRDDs
import org.apache.spark.sql.{types => T, functions => F}
import org.apache.spark.sql.Row
//
import spark.implicits._
val rdd = RandomRDDs.uniformRDD(spark.sparkContext, 100)
var df = rdd.toDF("A")
df = df.withColumn("id", F.monotonically_increasing_id())
@vietvudanh
vietvudanh / common_import.py
Created October 24, 2019 03:06
notebook_common_import
import os
import sys
import pandas as pd
import numpy as np
import matplotlib
from matplotlib import pyplot as plt
import seaborn as sns
from IPython.core.display import display, HTML
@vietvudanh
vietvudanh / data.py
Last active December 3, 2019 03:48
data snippets
def chunks(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n]
def chunks_iter(l, n):
it = iter(iterable)
while True:
chunk = tuple(itertools.islice(it, n))
if not chunk:
@vietvudanh
vietvudanh / describe.groovy
Created September 27, 2019 07:10 — forked from robertdale/describe.groovy
JanusGraph Schema Describe Command
// This can be imported via ./bin/gremlin.sh -i describe.groovy
// A variable 'graph' must be defined with a JanusGraph graph
// Run it as a plugin command ':schema'
// :schema describe
//
import org.janusgraph.graphdb.database.management.MgmtLogType
import org.codehaus.groovy.tools.shell.Groovysh
import org.codehaus.groovy.tools.shell.CommandSupport
@vietvudanh
vietvudanh / sublime-text-scopes.md
Created September 25, 2019 07:45 — forked from J2TEAM/sublime-text-scopes.md
Sublime Text 2/3: Snippet scopes

Here is a list of scopes to use in Sublime Text 2/3 snippets -

ActionScript: source.actionscript.2
AppleScript: source.applescript
ASP: source.asp
Batch FIle: source.dosbatch
C#: source.cs
C++: source.c++
Clojure: source.clojure
@vietvudanh
vietvudanh / tmux.conf
Created September 24, 2019 01:33
tmux config
# vim ~/.tmux.conf
# command prefix
unbind C-b
set-option -g prefix C-a
@vietvudanh
vietvudanh / manage.sh
Last active August 24, 2019 01:57
manage script in bash
#!/usr/bin/env bash
# template for maange script in bash
# provide listing functions / usage.. etc
CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# START vars
LOG_FILE="$CWD/log.log"
# END vars