Skip to content

Instantly share code, notes, and snippets.

View skinnyfads's full-sized avatar
🏠
Working from home

ir skinnyfads

🏠
Working from home
  • Kanagawa Prefecture
  • 06:51 (UTC +09:00)
  • Reddit u/skinnyfads
View GitHub Profile
@skinnyfads
skinnyfads / downloadFile.ts
Last active March 6, 2023 19:34
Download any files from direct link using Node.js
import fs from "node:fs";
import https from "node:https";
import http from "node:http";
function getFileName(url: string) {
return new URL(url).pathname.split("/").pop();
}
async function downloadFile(url: string): Promise<string> {
const urlProtocol = new URL(url).protocol;
const request = urlProtocol === "https:" ? https : http;
@skinnyfads
skinnyfads / conversation.py
Created February 10, 2023 04:33 — forked from MohammadHosseinGhorbani/conversation.py
Conversations in pyrogram (no extra package needed)
from pyrogram import Client, filters
app = Client('CONVERSATION_EXAMPLE')
conversations = {}
infos = {}
def conv_filter(conversation_level):
def func(_, __, message):
return conversations.get(message.from_user.id) == conversation_level
@skinnyfads
skinnyfads / main.js
Created February 6, 2023 18:52
Get all the json files from https://jlptstudy.net/
import fs from "node:fs";
import axios from "axios";
const baseUrl = "https://jlptstudy.net";
const pattern = /<a\s+(?:[^>]*?\s+)?href=(["'])(.*?)\1/g;
(async () => {
// stop at 1 cause jlptstudy.net doesn't have the kanji n1
for (let nNumber = 5; nNumber > 1; nNumber--) {
const dirname = "n" + nNumber;
@skinnyfads
skinnyfads / index.js
Created January 28, 2023 15:33 — forked from ajhsu/index.js
document.createElement proxy function
var __createElement__ = document.createElement;
document.createElement = function(tagName, options){
console.log(`Element <${tagName}> created.`);
return __createElement__.call(this, tagName, options);
};
@skinnyfads
skinnyfads / generateLeague.ts
Created January 24, 2023 16:47
league matches schedule on javascript [ typescript version ]
interface ISchedule {
homeTeam: ITeam;
awayTeam: ITeam;
}
interface ITeam {
name: string;
strength: number;
points: number[];
numericId: number;
@skinnyfads
skinnyfads / index.js
Created January 16, 2023 18:14
Get all value form data on submit
yourForm.onsubmit = (event) => {
event.preventDefault();
const formData = new FormData(yourForm);
for (const [key, value] of formData) {
console.log({ key, value });
}
};
@skinnyfads
skinnyfads / index.ts
Created January 15, 2023 07:52
Check if a string is valid MongoDB ObjectId
function validObjectId(text: string) {
const pattern = /[0-9a-fA-F]{24}/;
const match = text.match(pattern);
if (!match) return false;
return match[0] === text;
}
@skinnyfads
skinnyfads / robin.js
Created January 8, 2023 05:30 — forked from FarazPatankar/robin.js
Round robin, league matches schedule on javascript
let teams = [
'Tigers',
'Foofels',
'Drampamdom',
'Lakebaka'
]
const roundRobin = (teams) => {
let schedule = []
let league = teams.slice()
@skinnyfads
skinnyfads / useFetch.ts
Created January 7, 2023 12:46
React useFetch on TypeScript
const useFetch = (url: string, options: any) => {
const [response, setResponse] = useState<string | undefined>(undefined);
const [error, setError] = useState<unknown>(undefined);
const [abort, setAbort] = useState<() => void>(() => {});
useEffect(() => {
const fetchData = async () => {
try {
const abortController = new AbortController();
const signal = abortController.signal;