Skip to content

Instantly share code, notes, and snippets.

View zhangyuan's full-sized avatar

Yuan Zhang zhangyuan

  • Xi'an, China
  • 11:23 (UTC +08:00)
View GitHub Profile

Setup dev env on Ubuntu 22.04

Update sources

deb https://mirrors.163.com/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.163.com/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.163.com/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.163.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb https://mirrors.163.com/ubuntu/ jammy-backports main restricted universe multiverse
@zhangyuan
zhangyuan / doc.md
Last active August 25, 2022 13:16
setup devbox with multipass

Launch the instance

multipass launch --name devbox  -d 100G -m 4G

Shell into the instance:

multipass shell devbox
@zhangyuan
zhangyuan / cross-compilation.md
Last active October 24, 2021 16:49
Cross-compilation for Linux release from Mac OSX
  1. Install musl-cross
brew install FiloSottile/musl-cross/musl-cross
  1. Add x86_64-unknown-linux-musl
rustup target add x86_64-unknown-linux-musl
@zhangyuan
zhangyuan / sankey.py
Created August 2, 2021 08:28
Render sankey diagram with plotly
import pandas as pd
import plotly.graph_objects as go
def sankey(df, columns, measurement, title='Sankey Diagram'):
labels = set()
for column in columns:
labels = labels.union(set(df[column]))
labels = list(labels)
target_columns = []
@zhangyuan
zhangyuan / analyze.py
Created February 19, 2020 15:11
Extract the git commit stats for analysis
from git import Repo
import sys
import csv
def build_changes(repo):
changes = []
for commit in repo.iter_commits("master"):
for filename, stats in commit.stats.files.items():
changes.append([
@zhangyuan
zhangyuan / OverwriteCSVSink.scala
Created January 26, 2019 07:54
OverwriteCSVSink
package example
import org.apache.spark.sql.execution.streaming.Sink
import org.apache.spark.sql.sources.{DataSourceRegister, StreamSinkProvider}
import org.apache.spark.sql.streaming.OutputMode
import org.apache.spark.sql.{DataFrame, SQLContext, SaveMode}
class OverwriteCSVSink(sqlContext: SQLContext,
parameters: Map[String, String],
// npm i @kubernetes/client-node
const Extensions_v1beta1Api = require('@kubernetes/client-node/dist/api').Extensions_v1beta1Api;
const ENDPOINT = 'https://x.x.x.x'; // (IP CAN BE FOUND FROM RESPONSE OF GKE getCluster API)
const USERNAME = 'admin'; // (THIS CAN BE FOUND FROM RESPONSE OF GKE getCluster API)
const PASSWORD = ''; // THIS CAN BE FOUND FROM RESPONSE OF GKE getCluster API
const BASE64_ENCODED_CA = ''; // THIS CAN BE FOUND FROM RESPONSE OF GKE getCluster API
const BASE64_ENCODED_CERT = ''; // THIS CAN BE FOUND FROM RESPONSE OF GKE getCluster API
const container = require('@google-cloud/container');
const clusterClient = new container.v1.ClusterManagerClient({
credentials: {
"private_key": "",
"client_email": "",
}
});
const projectId = 'projectId';
@zhangyuan
zhangyuan / listNamespacedPod.js
Created May 1, 2018 20:22
make api calls to kubernetes cluster with nodejs and explicit configuration
// npm install @kubernetes/client-node
const clientWrapper = require('@kubernetes/client-node/dist/auth-wrapper');
const ENDPOINT = 'https://x.x.x.x';
const USERNAME = 'admin';
const PASSWORD = '';
const BASE64_ENCODED_CA = '';
const BASE64_ENCODED_CERT = '';
@zhangyuan
zhangyuan / render.js
Last active October 19, 2017 02:15
Save web page to PDF with selenium and PhantomJS.
// npm install selenium-webdriver phantomjs-prebuilt --save
const webdriver = require('selenium-webdriver')
async function render(driver, filename) {
return await driver.executePhantomJS(`this.render("${filename}")`);
}
const main = async () => {
const customPhantom = webdriver.Capabilities.phantomjs();