Skip to content

Instantly share code, notes, and snippets.

@chriselsner
chriselsner / nix-on-macos-catalina.md
Last active September 19, 2024 00:46
Nix on macOS Catalina

Nix on macOS Catalina

I'm writing this gist for my own records but it might help someone else too.

Installing Nix

Support for Catalina has improved a lot since the update was first rolled out.

Note: See the NixOS manual for discussion of the --darwin-use-unencrypted-nix-store-volume option.

@freifrauvonbleifrei
freifrauvonbleifrei / git_clone_ssh_through_reverse_tunnel.md
Created December 19, 2019 15:29
Getting ssh internet access for firewalled systems, such as HPC systems

Getting github access on a firewalled system

This approach, based on [0] and [1] lets me reverse-tunnel through the local machine, to get github (and other) access on protected machines, such as HPC compute systems.

I put these lines in my local ~/.ssh/config file

Host somehpcsocks
 ProxyCommand ssh -D 2020 localhost nc -q 1 localhost 22
@jimmychu0807
jimmychu0807 / string-conversion.rs
Created November 21, 2019 10:20
Conversion between String, str, Vec<u8>, Vec<char> in Rust
use std::str;
fn main() {
// -- FROM: vec of chars --
let src1: Vec<char> = vec!['j','{','"','i','m','m','y','"','}'];
// to String
let string1: String = src1.iter().collect::<String>();
// to str
let str1: &str = &src1.iter().collect::<String>();
// to vec of byte
@lillypad
lillypad / rsa.hpp
Last active August 4, 2024 12:30
OpenSSL RSA Encryption / Decryption C++ Wrapper
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#define CRYPTO_RSA_KEY_LEN_4096 4096
#define CRYPTO_RSA_KEY_LEN_2048 2048
#define CRYPTO_RSA_KEY_LEN_1024 1024
@islishude
islishude / k8s-install.md
Last active March 17, 2025 07:00
k8s-国内源安装

MOVE TO HERE

注意以下命令,需要切换到 root 后运行

安装 docker

首先确定已经安装完成 docker,如果没有安装可以使用以下脚本快速安装并配置:

@markheath
markheath / docker-compose-v1.yml
Last active February 4, 2025 09:18
Elasticsearch docker compose examples
version: '2.2'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.4.1
container_name: elasticsearch
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
@knqyf263
knqyf263 / redis_test.go
Last active May 16, 2023 14:11
go-redis pipeline
func TestRedis(t *testing.T) {
s, _ := testutil.PrepareTestRedis()
for i := 0; i < 10000; i++ {
s.Set("key"+strconv.Itoa(i), "hoge"+strconv.Itoa(i))
}
client := redis.NewClient(&redis.Options{Addr: s.Addr()})
// 普通にループ
result := map[string]string{}
for i := 0; i < 10000; i++ {
@Warchant
Warchant / sonarqube-docker-compose.yml
Last active December 7, 2024 03:37
docker-compose file to setup production-ready sonarqube
version: "3"
services:
sonarqube:
image: sonarqube
expose:
- 9000
ports:
- "127.0.0.1:9000:9000"
networks:
@zhiqiang21
zhiqiang21 / 移动端H5图片压缩上传.md
Created March 21, 2017 03:34
移动端h5图片压缩上传

移动端H5图片压缩上传

大体的思路是,部分API的兼容性请参照caniuse

  1. 利用FileReader,读取blob对象,或者是file对象,将图片转化为data uri的形式。
  2. 使用canvas,在页面上新建一个画布,利用canvas提供的API,将图片画入这个画布当中。
  3. 利用canvas.toDataURL(),进行图片的压缩,得到图片的data uri的值
  4. 上传文件。

步骤1当中,在进行图片压缩前,还是对图片大小做了判断的,如果图片大小大于200KB时,是直接进行图片上传,不进行图片的压缩,如果图片的大小是大于200KB,则是先进行图片的压缩再上传: