Skip to content

Instantly share code, notes, and snippets.

import argparse
import re
import sys
import time
import praw
CLIENT_ID = 'YOUR_CLIENT_ID'
CLIENT_SECRET = 'YOUR_CLIENT_SECRET'
REDDIT_USERNAME = 'your Reddit username'
import praw
CLIENT_ID = 'YOUR_CLIENT_ID'
CLIENT_SECRET = 'YOUR_CLIENT_SECRET'
REDDIT_USERNAME = 'your reddit username'
# https://www.reddit.com/r/singapore/comments/8eoesx/rsingapore_random_discussion_and_small_questions/
submission_id = '8eoesx'
reddit = praw.Reddit(client_id=CLIENT_ID, client_secret=CLIENT_SECRET,
import random
import re
def parse_text(text):
"""Returns a list of sentence chains extracted from text."""
text = text.strip()
sentences = []
for line in text.splitlines():
import string
import random
import time
chars = string.digits + string.ascii_letters + string.punctuation + ' '
iterations_per_character_revealed = 2
update_delay = 0.05
choices = ['Edmond To', 'Tu Yong Tan', 'Clement Chua', 'Wei Quan Ng']
@yi-jiayu
yi-jiayu / autoreplier.py
Last active January 27, 2024 11:09
Automatic replies for Telegram (Updated for Telethon 1.6.2)
import time
from telethon import TelegramClient, events
# sample API_ID from https://github.com/telegramdesktop/tdesktop/blob/f98fdeab3fb2ba6f55daf8481595f879729d1b84/Telegram/SourceFiles/config.h#L220
# or use your own
api_id = 17349
api_hash = '344583e45741c457fe1862106095a5eb'
# fill in your own details here
@yi-jiayu
yi-jiayu / skiing.py
Last active January 30, 2018 06:38
Solution for Skiing in Singapore - a coding diversion (http://geeks.redmart.com/2015/01/07/skiing-in-singapore-a-coding-diversion/)
#!/usr/bin/env python3
import os
import sys
from itertools import product
def read_map(s):
s = s.strip().split('\n')
l, w = (int(x) for x in s[0].split(' '))
@yi-jiayu
yi-jiayu / index.js
Last active November 6, 2017 12:45
Source code for a simple Telegram bot on Google Cloud Functions
exports.haha = function (req, res) {
const update = req.body;
console.log(JSON.stringify(update));
// update contains a message
if (update.hasOwnProperty('message')) {
// call the sendMessage method
const reply = {
method: 'sendMessage',
chat_id: update.message.chat.id,
'use strict';
const pokemon = require('./pokemon.min.json');
// check if id_or_name matches a pokemon's id or name
const match = (pokemon, id_or_name) => pokemon.id == id_or_name || pokemon.slug.includes(id_or_name.toLowerCase());
// find the first matching pokemon
const get_pokemon = id_or_name => pokemon.find(p => match(p, id_or_name));
@yi-jiayu
yi-jiayu / pokemon.min.json
Last active November 4, 2017 08:23
Pokédex data from https://www.pokemon.com/us/api/pokedex/kalos (ETag: W/"dbd66b428dafaf07005feaa5f1b97b85")
[{"abilities":["Overgrow"],"detailPageURL":"/us/pokedex/bulbasaur","weight":15.2,"weakness":["Fire","Flying","Ice","Psychic"],"number":"001","height":28.0,"collectibles_slug":"bulbasaur","featured":"true","slug":"bulbasaur","name":"Bulbasaur","ThumbnailAltText":"Bulbasaur","ThumbnailImage":"https://assets.pokemon.com/assets/cms2/img/pokedex/detail/001.png","id":1,"type":["grass","poison"]},{"abilities":["Overgrow"],"detailPageURL":"/us/pokedex/ivysaur","weight":28.7,"weakness":["Fire","Flying","Ice","Psychic"],"number":"002","height":39.0,"collectibles_slug":"ivysaur","featured":"true","slug":"ivysaur","name":"Ivysaur","ThumbnailAltText":"Ivysaur","ThumbnailImage":"https://assets.pokemon.com/assets/cms2/img/pokedex/detail/002.png","id":2,"type":["grass","poison"]},{"abilities":["Thick Fat"],"detailPageURL":"/us/pokedex/venusaur","weight":342.8,"weakness":["Fire","Psychic","Flying","Ice"],"number":"003","height":94.0,"collectibles_slug":"venusaur","featured":"true","slug":"venusaur","name":"Venusaur","Thumbnai
@yi-jiayu
yi-jiayu / count_messages.py
Last active January 21, 2024 15:17
Using Telethon and the Telegram API to count the number of messages in each of your recent conversations
from telethon import TelegramClient
from telethon.errors.rpc_errors_401 import SessionPasswordNeededError
# (1) Use your own values here
api_id = 17349
api_hash = '344583e45741c457fe1862106095a5eb'
phone = 'YOUR_NUMBER_HERE'
username = 'username'