Skip to content

Instantly share code, notes, and snippets.

View Elijah-trillionz's full-sized avatar
💭
hacking

Elijah Trillionz Elijah-trillionz

💭
hacking
View GitHub Profile
@Elijah-trillionz
Elijah-trillionz / annotations.ts
Created June 10, 2022 17:41
type annotations with "as" keyword
const animal: 'dog' | 'tiger' | 'lion' = 'dog';
const printDomesticAnimal = (animal: 'dog' | 'cat') => {
return animal;
}
printDomesticAnimal('tiger'); // bringing the tiger as tiger will be a problem
printDomesticAnimal('tiger' as 'dog'); // bringing the tiger as a dog
const filterPostsByPageIndex = (posts, pageIndex) => {
const postPerPage = 5;
// get the total posts from page 1 to current page
const totalPagePosts = pageIndex * postPerPage;
// get the total posts from page 1 to previous page
const prevPagePosts = totalPagePosts - postPerPage;
return posts.filter(
(post, index) => index < totalPagePosts && index >= prevPagePosts
@Elijah-trillionz
Elijah-trillionz / closures.js
Created April 28, 2022 09:19
what will it log
// what will it log
function foo(x) {
return function() {
x++;
console.log(x)
}
};
const x = 0;
const bar = foo(x);
@Elijah-trillionz
Elijah-trillionz / javascript.json
Created February 16, 2022 18:01
VSCode minimal snippets for working with styled-components
{
"Styled components file": {
"prefix": "stc",
"body": [
"import styled from 'styled-components'\n\nexport const ${1:${TM_FILENAME_BASE}} = styled.${2:div}`\n$0\n`;"
]
},
"Styled component": {
"prefix": "btc",
"body": ["export const ${1:Div} = styled.${2:div}`\n$0\n`;"]
@Elijah-trillionz
Elijah-trillionz / guess_game.py
Created November 26, 2021 19:10
Guessing game for computers
# guess number game for computers
import random as rd
# def guess_number():
# user_input = int(input('Enter a number for computer to guess btw 1 and 10 (inclusive): '))
# attempts = 2
#
# while attempts >= 0:
# is_wrong = compare_guess(user_input, attempts)
@Elijah-trillionz
Elijah-trillionz / generator.py
Created November 26, 2021 19:05
password generator with python
# password generator
import random as rd
alphabets = 'abcdefghijklmnopqrstuvwxyz'
numbers = '1234567890'
characters = '!@#$%^&*~'
def generate_random_char():
@Elijah-trillionz
Elijah-trillionz / main.py
Created November 25, 2021 02:05
guessing game for computers
# guess the number game. (computers)
import random as rd
def guess_number():
user_input = int(input('Enter a number for computer to guess btw 1 and 10 (inclusive): '))
attempts = 2
while attempts >= 0:
@Elijah-trillionz
Elijah-trillionz / main.py
Created November 25, 2021 01:54
guess number game (users)
# guess the number game.
import random as rd
def guess_number():
computer_input = rd.randint(1, 10)
attempts = 2
while attempts >= 0:
@Elijah-trillionz
Elijah-trillionz / removeProps.js
Created November 11, 2021 11:38
easily delete two or more properties from an object
const removeProps = (obj, ...propsName) => {
propsName.forEach((propName) => {
delete obj[propName]
})
}
@Elijah-trillionz
Elijah-trillionz / exercises.py
Created November 5, 2021 09:46
calculate number of days between two dates
# Write a Python program to calculate number of days between two dates.
# (2014, 7, 2), (2014, 7, 11)
import datetime as date
def num_of_days(date_one, date_two):
try:
(year, month, day) = date_one
new_date = date.datetime(year, month, day).timestamp()