Skip to content

Instantly share code, notes, and snippets.

@CarterTsai
CarterTsai / inlinepython.rs
Created April 18, 2020 16:22
inline python
#![feature(proc_macro_hygiene)]
use inline_python::python;
fn main() {
let who = "world";
let n = 5;
println!("== 1. Hello World ==");
python! {
for i in range('n):
print(i, "Hello", 'who)
@CarterTsai
CarterTsai / main.rs
Created April 14, 2020 15:36
引用libhello的library
extern crate hello;
fn main() {
hello::world();
hello::you_can_say();
hello::say();
}
@CarterTsai
CarterTsai / hello.rs
Created April 14, 2020 15:34
hello library
// public function
pub fn world() {
println!("say world");
}
// private_function
fn say() {
println!("hello world`");
}
@CarterTsai
CarterTsai / struct.rs
Created April 13, 2020 14:58
rust struct
fn main() {
// 結構
// https://doc.rust-lang.org/rust-by-example/custom_types/structs.html
#[derive(Debug)]
struct User {
username: String,
email: String,
}
@CarterTsai
CarterTsai / vector.rs
Created April 12, 2020 16:41
rust_vector
#![feature(vec_remove_item)]
fn main() {
// vector是一個重新調整size的array(類似c#裡面的list), 他的size在編譯時期
// 是不會知道。但他可以在任何時間增大或減少size, 然後vector只能儲存相同類型的值
// 建立vector的方式
println!("== 1. 建立vector的方式 ==");
let v = vec![1, 2, 3];
println!("v => {:?}", v);
@CarterTsai
CarterTsai / hash.rs
Last active April 11, 2020 17:09
rust hashmap example
// https://learning-rust.github.io/docs/e4.unwrap_and_expect.html
use std::collections::HashMap;
fn main() {
// 範例一
let mut inventory = HashMap::new();
// 設定預設值
let inventory_default = 0;
// 加入資料到HashMap
inventory.insert(String::from("Notebook"), 10);
@CarterTsai
CarterTsai / test_es6.html
Created March 18, 2020 15:17
test_es6_on_ie
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.8.7/polyfill.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
@CarterTsai
CarterTsai / babel_in_browser.html
Created March 18, 2020 15:15
babel_in_browser
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.8.7/polyfill.js">
</script><script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
@CarterTsai
CarterTsai / aopstart.cs
Created February 16, 2020 02:40
aop using
using System;
namespace aoptest
{
class Program
{
static void Main(string[] args)
{
var decoratedAPI = LoggerDecorator<IHttpApi>.Create(new HttpApi());
decoratedAPI.Get("https://www.google.com");
@CarterTsai
CarterTsai / aop.cs
Last active February 14, 2020 23:23
aop sample
using System;
using System.Reflection;
using System.Text.Json;
namespace Sample.AOPProxy
{
public class LoggerDecorator<T> : DispatchProxy
{
private T _decorated;
public static T Create(T decorated)