Skip to content

Instantly share code, notes, and snippets.

View libchaos's full-sized avatar
💭
I may be slow to respond.

libchaos libchaos

💭
I may be slow to respond.
View GitHub Profile
@libchaos
libchaos / golang
Created September 15, 2021 06:39
JSON_to_struct
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)
type UserList struct {
#![cfg_attr(not(feature = "std"), no_std)]
// a module for proof of existence
pub use pallet::*;
#[frame_support::pallet]
pub mod pallet {
use frame_support::{dispatch::DispatchResultWithPostInfo, pallet_prelude::*};
use frame_system::pallet_prelude::*;
use sp_std::vec::Vec;
@libchaos
libchaos / substrate homework3
Created May 28, 2021 02:42
rust tpc server
use std::thread;
use std::net::{TcpListener, TcpStream, Shutdown};
use std::io::{Read, Write};
use std::str;
fn handle_client(mut stream:TcpStream) {
let mut data = [0 as u8; 50]; // 设置50个字节的数据缓冲区, 传输的数据被按50个字节切割
while match stream.read(&mut data) { // match表达式返回true或者false 控制空循环
Ok(size) => { // 当前的数据缓冲块的长度
println!("size is {}", size);
enum TrafficTight {
Red,
Green,
Yellow,
}
impl TrafficTight {
fn time(&self) -> u8 {
@libchaos
libchaos / server.js
Last active August 16, 2018 12:26
node
app.get('/dog/age/:age', (req, res) => {
redis.lrange('dog:age:' + req.params.age)
.then((data) => Promise.all(data.map(redis.hgetall)))
.then((data) => res.send(data));
console.timeEnd('request');
})
app.get('/dog/age/:age', (req, res) => {
redis.lrange('dog:age:'+req.params.age)
.then((data)=> {
@libchaos
libchaos / 0_reuse_code.js
Created February 27, 2017 07:41
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
# hit
## hello
![http://lorempixel.com/125/125/animals/9/cc]