Skip to content

Instantly share code, notes, and snippets.

@osharaki
osharaki / main.dart
Created January 3, 2023 12:26
Page scrolling with Scrollable.ensureVisible()
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
@osharaki
osharaki / main.dart
Created January 3, 2023 12:26
obsidian-dawn-7748
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
@osharaki
osharaki / main.dart
Created September 26, 2022 12:59
sparkling-durian-3398
void main() {
final myMap ={"foo":1};
print(myMap["bar"]);
}
@osharaki
osharaki / cli_arguments.py
Last active May 3, 2021 16:51
Unogs API miner: CLI arguments (snippet 6/6)
def init_cli(default_buffer, default_time):
parser = argparse.ArgumentParser()
parser.add_argument(
"-b",
dest="buffer",
type=buffer_type,
default=default_buffer,
metavar="[0-100]",
help=f"The number of requests [{0}-{100}] from the daily quota to leave remaining (i.e. unconsumed). Defaults to {default_buffer}",
)
@osharaki
osharaki / _cli.py
Last active May 3, 2021 17:18
Unogs API miner: command-line interface
"""
Functions to set up the command line interface.
Raises:
argparse.ArgumentTypeError: Raised if request buffer is out of range
argparse.ArgumentTypeError: Raised if time is neither "now" nor HH:mm
argparse.ArgumentTypeError: Raised if time is out of correct range
argparse.ArgumentTypeError: Raised if offset is negative or not multiple
of 100
@osharaki
osharaki / cli_types.py
Created May 3, 2021 14:43
Unogs API miner: CLI type functions (snippet 5/6)
import argparse
import re
# Allows for more control over the error message in the case of invalid arguments
def buffer_type(value, min=0, max=100):
value = int(value)
if min <= value <= max:
return value
else:
raise argparse.ArgumentTypeError(
@osharaki
osharaki / unogs_miner_scheduler.py
Last active May 3, 2021 14:40
Unogs API miner: task scheduler (snippet 4/6)
if args.exec_time == "now":
job()
if not done:
# Prevent scheduling in case of permanent termination
schedule.every().day.at(default_time).do(job)
else:
schedule.every().day.at(args.exec_time).do(job)
while True:
if done:
@osharaki
osharaki / unogs_miner_job.py
Last active May 3, 2021 14:40
Unogs API miner: main execution task (snippet 3/6)
def job():
global remaining_quota
global offset
global done
count = 0
while int(remaining_quota) - buffer > 0:
querystring["offset"] = str(offset)
response = requests.request("GET", url, headers=headers, params=querystring)
if response:
content = response.json()
@osharaki
osharaki / unogs_miner_setup_2.py
Last active May 3, 2021 14:40
Unogs API miner: API request variables (snippet 2/6)
url = "https://unogsng.p.rapidapi.com/search" # endpoint
querystring = {"orderby": "date", "subtitle": "english"} # only retrieve shows with English subs and order results by date added
# TODO: add API key
headers = {
"x-rapidapi-key": "insert-api-key-here",
"x-rapidapi-host": "unogsng.p.rapidapi.com",
}
@osharaki
osharaki / unogs_miner_setup_1.py
Last active May 3, 2021 14:40
Unogs API miner: imports, CLI init, and global vars (snippet 1/6)
import time # sleep operations
import requests # API requests
import json # storing data
import schedule # scheduling tasks
from _cli import init_cli # Command-line interface
default_buffer = 15 # default number of daily requests to be left unconsumed
default_time = "21:35" # script execution time defaults to quota reset time
args = init_cli(default_buffer, default_time) # initialize CLI