Skip to content

Instantly share code, notes, and snippets.

@Jacobbishopxy
Jacobbishopxy / generic_into_iterator_test.rs
Created June 7, 2022 02:36
Rust generic iterable function parameter
#[test]
fn generic_into_iterator() {
fn f1<'a, I, T>(iter: I)
where
I: IntoIterator<Item = &'a T>,
T: 'a + std::fmt::Debug,
{
for i in iter.into_iter() {
println!("{:?}", i);
}
@Jacobbishopxy
Jacobbishopxy / rs_2021_binding.rs
Created October 22, 2021 12:57
Rust version 2021 new behavior: `@` binding
#[test]
fn test_dev() {
#[derive(Debug)]
struct Foo {
a: i32,
b: String,
}
impl Foo {
fn new(a: i32, b: &str) -> Self {
@Jacobbishopxy
Jacobbishopxy / Install.md
Last active June 15, 2021 01:05
Install Go on Ubuntu

Install Go on Ubuntu

  1. download tar file, choose a Golang version and replace it (go1.16.5)

    curl -O https://storage.googleapis.com/golang/go1.16.5.linux-amd64.tar.gz
  2. extract tar

@Jacobbishopxy
Jacobbishopxy / Cargo.toml
Created May 16, 2021 02:37
Rust encryption: hash + verify
[dependencies]
ring = "0.16.20"
@Jacobbishopxy
Jacobbishopxy / LocalStorageHelper.ts
Last active August 13, 2020 09:19
A local storage helper for typescript
/**
* Created by Jacob Xie on 8/12/2020.
*/
import _ from 'lodash';
import * as moment from 'moment';
export interface StorageValue {
data: Object,
expiry?: moment.Moment
@Jacobbishopxy
Jacobbishopxy / CallChildFuncFromParent.tsx
Last active August 13, 2020 09:24
A React example for calling child function from parent component
/**
* Created by Jacob Xie on 8/7/2020.
*
* Simple call child function from parent
*/
import React, {
forwardRef,
useImperativeHandle,
useRef