Skip to content

Instantly share code, notes, and snippets.

View DawChihLiou's full-sized avatar

Daw-Chih Liou DawChihLiou

View GitHub Profile
@DawChihLiou
DawChihLiou / Convert .mov or .MP4 to .gif.md
Created November 15, 2022 17:54 — forked from SheldonWangRJT/Convert .mov or .MP4 to .gif.md
Convert Movie(.mov) file to Gif(.gif) file in one command line in Mac Terminal

This notes is written by Sheldon. You can find me with #iOSBySheldon in Github, Youtube, Facebook, etc.

Need

Convert .mov/.MP4 to .gif

Reason

As a developer, I feel better to upload a short video when I create the pull request to show other viewers what I did in this PR. I tried .mov format directly got after finishing recording screen using Quicktime, however, gif offers preview in most web pages, and has smaller file size.

This is not limited to developer, anyone has this need can use this method to convert the files.

BinaryTree::new(1)
.left(
BinaryTree::new(2)
.left(BinaryTree::new(4))
.right(BinaryTree::new(5))
)
.right(BinaryTree::new(3))
#[test]
fn insert() {
let mut tree = BinaryTree::new(1);
tree.insert(2);
tree.insert(3);
tree.insert(4);
tree.insert(5);
assert_eq!(
tree,
BinaryTree::new(1)
#[test]
fn create_new_tree_with_from() {
// `BinaryTree::from` takes in a reference of an array because borrowing is sufficient
let tree = BinaryTree::from(&[1, 2, 3, 4, 5, 6]);
assert_eq!(
tree,
BinaryTree::new(1)
.left(
BinaryTree::new(2)
.left(BinaryTree::new(4))
@DawChihLiou
DawChihLiou / lib_from.rs
Created January 14, 2022 08:47
`BinaryTree::from` implementation
impl<T> BinaryTree<T> {
pub fn from(new_values: &[T]) -> Self {
let (first, rest) = new_values.split_first().unwrap();
let mut root: BinaryTree<T> = BinaryTree::new(*first);
for value in rest {
root.insert(*value)
}
root
}
}
@DawChihLiou
DawChihLiou / lib.rs
Last active January 14, 2022 08:46
Binary Tree Insertion in Rust
#[derive(Debug, PartialEq)]
pub struct BinaryTree<T> {
pub value: T,
pub left: Option<Box<BinaryTree<T>>>,
pub right: Option<Box<BinaryTree<T>>>,
}
impl<T> BinaryTree<T>
where
T: Copy,
{
fn is_palindrome(str: String) -> bool {
let mut chars = string.bytes();
while let Some((front, back)) = chars.next().zip(chars.next_back()) {
if front != back {
return false;
}
}
true
}
const encoder = new TextEncoder()
const decoder = new TextDecoder()
const bytes = encoder.encode('\u0061\u0301')
decoder.decode(bytes) // 'á'
function isPalindrome(str: string): boolean {
return str === str.split('').reverse().join('')
}
/*
* lp rp
* | |
* v → ← v
* "aabbccbbaa"
*/
function isPalindrome(str: string): boolean {
let lp = 0
let rp = str.length - 1
while (lp < rp) {