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 / escape_sequences.c
Created July 19, 2016 09:09
Manipulating a compatible terminal using escape sequences
#include <stdio.h>
main(void) {
\\ enter alternate screen mode
printf("\033[?1049h");
\\ move the cursor to the upper left corner
printf("\033[H");
printf("Hello, World");
@yi-jiayu
yi-jiayu / ssh-invalid-users.sh
Created September 19, 2016 05:51
Displays a sorted list of users used in failed SSH login attempts
sudo cat /var/log/secure | grep invalid | awk '{ print $9 }' | sort | uniq -c | sort -bnr | less
@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:

import signal
import sys
from google.cloud import language
from google.api_core.exceptions import InvalidArgument
# create a Google Cloud Natural Languague API Python client
client = language.LanguageServiceClient()
@yi-jiayu
yi-jiayu / index.js
Created July 5, 2017 03:11
Using Google Cloud Functions to display data from Google Analytics as a README badge
"use strict";
const google = require('googleapis');
const key = require('./credentials.json');
const viewId = 'YOUR_VIEW_ID';
function getUsers(key, viewId) {
// https://github.com/google/google-api-nodejs-client#using-jwt-service-tokens
const jwtClient = new google.auth.JWT(