Skip to content

Instantly share code, notes, and snippets.

@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
@fuzunspm
fuzunspm / typescript.el
Created June 13, 2019 07:47
Emacs Typescript Setup for ReactJS, NextJS or NestJS
;;; typescript.el --- typescript support
;;; Commentary:
;;; Code:
(use-package flycheck
:ensure t
:config
(add-hook 'typescript-mode-hook 'flycheck-mode))
(defun setup-tide-mode ()
@akm
akm / file0.go
Created August 28, 2017 05:05
Goでの三項演算子っぽい書き方 ref: http://qiita.com/akm/items/1842f7c5b9755829886a
package main
import "fmt"
func main() {
foo := map[bool]string{true: "OK", false: "NG"}[2 > 1]
fmt.Printf("foo: %v\n", foo)
}
@rizo
rizo / Dockerfile
Last active August 27, 2024 11:25
Alpine (3.6) based docker image with Protocol Buffers compiler supporting Go.
# Protobuf Builder
# ================
#
# This image builds protocol buffers library from source with Go generation
# support. The builder and runner images are produced.
# Builder Image
# -------------
FROM golang:1.8.3-alpine3.6 as builder
@ca0v
ca0v / debounce.ts
Last active May 27, 2025 07:32
Typescript Debounce
// ts 3.6x
function debounce<T extends Function>(cb: T, wait = 20) {
let h = 0;
let callable = (...args: any) => {
clearTimeout(h);
h = setTimeout(() => cb(...args), wait);
};
return <T>(<any>callable);
}
/**
* Base contract that all upgradeable contracts should use.
*
* Contracts implementing this interface are all called using delegatecall from
* a dispatcher. As a result, the _sizes and _dest variables are shared with the
* dispatcher contract, which allows the called contract to update these at will.
*
* _sizes is a map of function signatures to return value sizes. Due to EVM
* limitations, these need to be populated by the target contract, so the
* dispatcher knows how many bytes of data to return from called functions.
@Rican7
Rican7 / conventional-json.go
Last active November 27, 2023 07:10
Marshal JSON in Golang using common lower-snake-case object key conventions
package main
import (
"bytes"
"encoding/json"
"fmt"
"regexp"
"time"
)