Skip to content

Instantly share code, notes, and snippets.

View Yigaue's full-sized avatar
🦍
building

Gospel Lekia Yigaue

🦍
building
View GitHub Profile
@Yigaue
Yigaue / handle-handlerfunc-handlefunc.md
Last active April 21, 2023 13:07
Note on Handle, HandleFunc and HandlerFunc in Go or Golang

Note on Handle, HandleFunc and HandlerFunc in Go or Golang

Handle:

Handle is a method with ServeMux(struct) as receiver, and takes two argument, pattern(string) and a handler(Handler).

func (mux *ServeMux) Handle(pattern string, handler Handler) {
      // implementation here.
}
@Yigaue
Yigaue / unicode-ascii-utf-8.md
Last active April 4, 2023 22:01
What is the difference between Unicode, ASCII and UTF-8

Unicode and ASCII are both character encoding standards, while UTF-8 (Unicode Transformation Format-8) is a specific implementation of Unicode. Here are the main differences between the three:

Character set: ASCII is a 7-bit encoding scheme that can represent 128 characters, while Unicode is a much larger character set that can represent almost all the characters used in any language. UTF-8 is a way of encoding Unicode characters in a specific format that allows for efficient storage and transmission.

Encoding scheme: ASCII uses a fixed-length encoding scheme, where each character is represented using 7 bits (or one byte) of data. Unicode uses a variable-length encoding scheme, where characters can be represented using 1 to 4 bytes of data, depending on the character's Unicode value. UTF-8 is also a variable-length encoding scheme, but it uses a specific algorithm to encode Unicode characters in a way that is backward-compatible with ASCII.

Multilingual support: ASCII is primarily used for representing ch

@Yigaue
Yigaue / Golang note
Last active February 17, 2023 15:14
See in action on playground https://play.golang.org/p/8zBXTbZR88f
package main
import (
"fmt"
)
var child string // Declared(type must be specified)
/*---------------NOTE-------------------------
@Yigaue
Yigaue / Permeability.php
Created October 30, 2020 11:52
Prosper Permeability algorithm
$permeabilityArray = [9230, 5940, 3080, 2860, 2790, 2370, 1464, 594, 593, 526, 500, 366];
/**
* Each number in the array should take turns to divided it self and every other number in the array,
* and a number can only divide itself or a number that has index greater than it.
* E.g 9230 can divide itself and every other number. 3080 can not divide 5940, and 9230 but can divide
* 2860, 2790, 2370, 1464, 594, 593, 526, 500, and 366.
* Print result different set of arrays.
*/
let data = [
{id: 1, title: 'Nite watch', price: 33, discount:0},
{id: 2, title: 'what I want', price: 12, discount:0.4},
{id: 3, title: 'Mercy at last', price: 405, discount:0.25},
{id: 4, title: 'Nothting between', price: 550, discount:0}
];
priceSum = data.reduce((acc, currentValue) => acc + currentValue.price, 0);
console.log(priceSum);
// console result
1000
let data = [
{id: 1, title: 'Nite watch', price: 33, discount:0},
{id: 2, title: 'what I want', price: 12, discount:0.4},
{id: 3, title: 'Mercy at last', price: 405, discount:0.25},
{id: 4, title: 'Nothting between', price: 550, discount:0}
];
let discountedBooks = data.every(item => item.discount > 0 );
console.log(discountedBooks);
// result
let data = [
{id: 1, title: 'Nite watch', price: 33, discount:0},
{id: 2, title: 'what I want', price: 12, discount:0.4},
{id: 3, title: 'Mercy at last', price: 405, discount:0.25},
{id: 4, title: 'Nothting between', price: 550, discount:0}
];
let discountedBooks = data.some(item => item.discount > 0 );
console.log(discountedBooks);
// result
let data = [
{id: 1, title: "Don't Waste your life ", price: 33, Author: "John Piper"},
{id: 2, title: "Living for a greater purpose", price: 12, Author: "JH Baritam"},
{id: 3, title: "The call for Mercy", price: 405, Author: "Lekia Yiga"},
{id: 4, title: "Heart Blindness", price: 550, Author: "Unknown author"}
];
let discountedBooks = data.find(item => item.price > 100);
console.log(discountedBooks);
// result
let data = [
{id: 1, title: "Don't Waste your life ", price: 33, Author: "John Piper"},
{id: 2, title: "Living for a greater purpose", price: 12, Author: "JH Baritam"},
{id: 3, title: "The call for Mercy", price: 405, Author: "Lekia Yiga"},
{id: 4, title: "Heart Blindness", price: 550, Author: "Unknown author"}
];
let discountedBooks = data.filter(item => item.price > 100);
console.log(discountedBooks);
//result
/*
data.map(item => {
if (item.price > 100) {
return {
id: item.id,
title: item.title,
price: item.price * (1 - 0.2)
};
}
return item;
});