Skip to content

Instantly share code, notes, and snippets.

View gengkev's full-sized avatar

Kevin Geng gengkev

  • Carnegie Mellon University
View GitHub Profile
@gengkev
gengkev / README.md
Last active July 17, 2017 15:12
Jekyll scripts for working on Director (TJ IOI website)

These scripts are located in /web/activities/tjioi/private/, and they compile the TJ IOI website from the /web/activities/tjioi/private/tjioi into the ../public/ directory.

Keybase proof

I hereby claim:

  • I am gengkev on github.
  • I am gengkev (https://keybase.io/gengkev) on keybase.
  • I have a public key ASCyeo8YPHFAnOkbcK-HKuU96sM1qZ14pgWuT0eaFxQ80wo

To claim this, I am signing this object:

@gengkev
gengkev / prime_sieve.py
Last active February 21, 2016 19:27
Quick way to list prime numbers using an Eratosthenes sieve
# Returns a list of all prime numbers less than N
def list_primes(N):
if N <= 0:
raise ValueError('%d is out of bounds' % N)
elif N <= 2:
return []
is_prime = [True] * N
@gengkev
gengkev / ioexception_writeup.md
Last active November 12, 2015 02:08
Writeup for IOException in EasyCTF 2015 by µ’s

Writeup for the IOException recon problem in EasyCTF 2015 by µ’s

By googling "ioexception michael zhang" and "ioexception osu", we find:

The MuseScore profile leads us to a blog on WordPress.com. Upon examining the picture in the header of the website, we discover that its filename is ioexception_recon.png. If we examine this file with a tool to read EXIF data such as Jeffrey's Exif Viewer, we discover part 1 embedded in the picture as an EXIF comment.

@gengkev
gengkev / heap_priority_queue.js
Last active October 4, 2015 22:09
A binary heap-based priority queue, written in JavaScript, supporting only unique values but allowing O(log n) remove and update.
(function(global) {
/**
* Constructor for a binary heap-based Priority Queue.
* Because this priority queue supports the remove and update operations in
* O(log n) time, all values must be unique and usable as object keys.
* Weird things may happen if you insert different types, or insert more
* than 2**31 objects. Don't use this for anything serious.
*/
function PriorityQueue(initial_list, cmp_func) {
@gengkev
gengkev / consecutiveheadstails.js
Last active December 26, 2015 17:29
a simulation for discussion 11 problem 3 in data analysis packet B, tjhsst 2013-14. it generates 4000 heads/tails combinations and counts how many appear consecutively, and how many times. to run, copy and paste this into a javascript console to run, i wrote it rather quickly!
var arr = [];
for (var i = 0; i < 4000; i++) {
if (Math.random() < 0.5) arr.push("H");
else arr.push("T");
}
var str = arr.join("");
var bla = str.match(/(H+|T+)/g);
var tab = {};
for (var i = 0; i < bla.length; i++) {
if (typeof tab[bla[i]] == "undefined") {
@gengkev
gengkev / randInt.js
Last active October 3, 2015 02:28
Random integers in JavaScript...just because it got annoying.
function randInt(min,max){
var range = max - min;
// it actually does work the other way...
// if (range < 0) { throw new RangeError("min must be less than max"); }
var rand = Math.floor(Math.random() * (range + 1));
return min + rand;
}
@gengkev
gengkev / fullscreen.js
Created April 4, 2012 15:41
fullscreen api
function toggleFullScreen(el,override) {
if (override == true) {
el = (el instanceof Element) ? el : document.documentElement;
[ "requestFullscreen",
"requestFullScreen",
"mozRequestFullScreen",
"webkitRequestFullscreen",
"webkitRequestFullScreen",
@gengkev
gengkev / uint8clampedarray.js
Created April 3, 2012 20:45
Uint8ClampedArray shim
if (!window.Uint8ClampedArray && window.Uint8Array && window.ImageData) {
window.Uint8ClampedArray = function(input,arg1,arg2) {
var len = 0;
if (typeof input == "undefined") { }
else if (!isNaN(parseInt(input.length))) { //an array, yay
len = input.length;
}
else if (input instanceof ArrayBuffer) {
return new Uint8ClampedArray(new Uint8Array(input,arg1,arg2));
}
@gengkev
gengkev / index.html
Created March 30, 2012 19:33 — forked from antimatter15/regeression.js
Linear Regression
<!doctype html>
<meta charset="UTF-8" />
<script src="linreg.js"></script>
<title>Linear Regressions in JS</title>
<script>
function $(d){return document.getElementById(d)};
var canvas, textarea, func = "linreg";
window.onload = function(){
canvas = document.getElementById("view");
textarea = document.getElementsByTagName("textarea")[0];