Skip to content

Instantly share code, notes, and snippets.

View growvv's full-sized avatar

Growvv growvv

View GitHub Profile
@growvv
growvv / run_test.sh
Created June 12, 2022 11:24
Testing your K8s apps with KIND
#!/usr/bin/env bash
NAME="test-cluster"
echo "+++ Cleaning up old test artififacts"
kubectl delete cluster --name "${NAME}" > /dev/null 2>&1 || true
rm sample-controller > /dev/null 2>&1 || true
echo "+++ Creating test cluster"
kind create cluster --name "${NAME}" --config kind-config.yaml
@growvv
growvv / work_queue.cpp
Created December 26, 2021 15:22
基于互斥锁和条件变量的线程池
#include<pthread.h>
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<functional>
#include<queue>
#include<iostream>
typedef std::function<void()> func;
@growvv
growvv / server.go
Last active December 17, 2021 07:58
基于uthread库的协程echo server,与go协程写法基本一致
package main
import (
"fmt"
"net"
)
func main() {
fmt.Println("Starting the server ...")
// 创建 listener
@growvv
growvv / red_black_tree.cpp
Created December 16, 2021 14:10
用copilot生成的红黑树
#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
struct Node
{
int data;
Node *left;
@growvv
growvv / interface.go
Created December 4, 2021 08:09
copilot自动补全的go interface例子
package main
import "fmt"
type I interface {
M()
}
type T struct {
S string
@growvv
growvv / adversarial_attack.py
Created November 10, 2021 06:50
使用FGSM方法生成对抗样本
from __future__ import print_function
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torchvision import datasets, transforms
import numpy as np
import matplotlib.pyplot as plt
import ipdb
@growvv
growvv / open_file.rs
Created September 26, 2021 07:19
open a file by match or closure
use core::panic;
use std::fs::File;
use std::io::ErrorKind;
fn main(){
let path = "a.txt";
let f = File::open(path);
let f = match f {
Ok(file) => file,
Err(error) => match error.kind() {
@growvv
growvv / printn.c
Created September 6, 2021 13:49
打印整数n的b进制
/*
* Print an unsigned integer in base b.
*/
printn(n, b)
long n;
{
register long a;
if (n<0) { /* shouldn't happen */
putchar('-');
@growvv
growvv / send_email.py
Created August 12, 2021 12:38
发送邮件Python函数
from smtplib import SMTPException, SMTP_SSL
from email.mime.text import MIMEText
from email.header import Header
email_to = "xx@qq.com"
email_from = "xxx@qq.com"
smtp = "xxxx"
@growvv
growvv / RxDemo-01.swift
Last active March 5, 2021 10:28
仿写ReSwift接口
print("Start")
enum Event<Element>{
case next(Element)
case error(Error)
case complete
}
protocol ObserverType {
associatedtype Element