Skip to content

Instantly share code, notes, and snippets.

@yi-jiayu
yi-jiayu / echoHttpRequest.js
Created September 24, 2015 16:32 — forked from Marak/echoHttpRequest.js
Echo HTTP requests
module['exports'] = function echoHttp (hook) {
console.log("Console messages are sent to /logs");
console.log(hook.params);
console.log(hook.req.path);
console.log(hook.req.method);
@yi-jiayu
yi-jiayu / btoh.py
Last active November 26, 2015 09:20
from collections import namedtuple
Disk = namedtuple('Disk', ['size', 'colour'])
class BicolorTowersOfHanoi(object):
def __init__(self, disks=3):
self._disks = disks
self._moves = 0
self._towers = {1: [], 2: [], 3: []}
@yi-jiayu
yi-jiayu / math-battle-script.js
Created October 5, 2016 16:23
Automated script to play the Telegram Gaming Platform demo game Math Battle when played in a browser using devtools. May cause highscore ban.
var target = document.getElementById('task');
var observer = new MutationObserver(function(mutations) {
var x = parseInt(document.querySelector('#task_x').textContent, 10);
var y = parseInt(document.querySelector('#task_y').textContent, 10);
var op = document.querySelector('#task_op').textContent;
var eq = parseInt(document.querySelector('#task_res').textContent, 10);
console.log(x, y, op, eq);
var correct = false;
@yi-jiayu
yi-jiayu / day-03.py
Created December 5, 2016 12:57
Day 3 solution for Advent of Code 2016 as it was when I submitted my answer
from hashlib import md5
secret = 'reyedfim'
nonce = 0
digits = []
passwd = [None] * 8
while not all(passwd):
hash = md5()
hash.update('{}{}'.format(secret, nonce).encode('utf-8'))
@yi-jiayu
yi-jiayu / teammates.js
Created April 4, 2017 09:30
TEAMMATES quick feedback script
var boxes = document.querySelectorAll('.numScaleAnswerBox');
var textBoxes = document.querySelectorAll('.mce-content-body');
[].forEach.call(boxes, function(box) {
box.value = 5;
});
[].forEach.call(textBoxes, function(box) {
box.textContent = 'Great';
});

Keybase proof

I hereby claim:

  • I am yi-jiayu on github.
  • I am jiayu1 (https://keybase.io/jiayu1) on keybase.
  • I have a public key whose fingerprint is 6063 3A56 D1AD 52CE 15E7 194B F834 9771 097D 0610

To claim this, I am signing this object:

@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
'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 / 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,
@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(' '))