Skip to content

Instantly share code, notes, and snippets.

View a-gu's full-sized avatar
Last seen in 1 hr

Andrew Gu a-gu

Last seen in 1 hr
View GitHub Profile
@a-gu
a-gu / zip_compare.py
Created March 18, 2017 03:10
Compares directory/file tree structure in two compressed files
#/usr/bin/python
"""
zip_compare.py
Compares directory/file tree structure in two compressed files. Designed for
archives labeled "Semester Course Version.zip".
Distrubuted under the terms of the
GNU GPL-3.0+ License <http://www.gnu.org/licenses/gpl-3.0.txt>
Copyright (C) 2017 Andrew Gu
@a-gu
a-gu / test_inf-scroll.py
Created March 23, 2017 15:36
A quick example to demonstrate loading infinite-scroll elements with Selenium and retrieving data from the page.
#/usr/bin/python
"""
test_inf-scroll.py
---
A quick example to demonstrate loading infinite-scroll elements with Selenium
and retrieving data from the page.
"""
from selenium import webdriver
import time
@a-gu
a-gu / pdf-uncheck.js
Created April 5, 2017 16:33
Allow radio elements in PDF forms to be unchecked
// Source: https://answers.acrobatusers.com/Unable-to-uncheck-the-checked-option-box-q197757.aspx
if (event.target.lastVal == event.target.value) {
event.target.lastVal = null;
event.target.value = "Off";
} else {
event.target.lastVal = event.target.value;
}
<?php
// Don't forget to make this file private (.htaccess)
$file_path = "./users.txt";
function auth_check($user, $pass) {
$file = file($GLOBALS["file_path"]);
// Find lines identifying the specified user
$user_enc = base64_encode($user);
$user_regex = "/^{$user_enc}::.*$/";
@a-gu
a-gu / read_hist.m
Created September 13, 2017 02:52
Reads MATLAB command history, returns a structure usable in programs
%% read_hist
%
% Reads MATLAB command history, returns a structure usable in programs
%
% Returns a MATLAB structure:
%
% - First level structure references by 's#' where '#' is the index of
% index of the session where commands are run (starting from 1)
% - Second level structure references by 'c#' where '#' is the index of
% the command run in the session (starting from 1). The first command
@a-gu
a-gu / materialize_extend.js
Last active September 16, 2017 15:09
Extends the Materialize.css jQuery API for chips widgets
jQuery.fn.extend({
// Materialize Chips
'addChip': function (chips) {
this.data('chips', this.data('chips').concat(chips));
let to_add = [],
new_chip = function(name) {
return div = $('<div>').text(name).attr('class', 'chip').append($('<i>').text('close').attr('class', 'material-icons close'));
};
if (typeof chips === 'string') { // single string
to_add.push(chips);
@a-gu
a-gu / mathjax.user.js
Created November 1, 2017 21:30
Injects MathJax into all pages, and begin auto-rendering
// ==UserScript==
// @name MathJax
// @namespace https://www.mathjax.org/
// @version 1.0
// @description Injects MathJax into all pages, and begin auto-rendering
// @author Andrew Gu
// @match *://*/*
// @grant none
// ==/UserScript==
@a-gu
a-gu / sp17_me318m_lab08_01_01.matlab
Created November 5, 2017 22:50
Spring 2017 - M E 318M: Lab 8 Problem 1.1
% Plot amplitude vs. distance
dist = [0.15, 1.04:0.4:4.24];
ampl = [7.5, 5.6, 4.4, 3.6, 3.0, 2.5, 2.2, 1.9, 1.5, 1.1];
scatter(dist, ampl);
% Overlay Equation 1.1
hold on;
x = [0.15, 4.24];
y = -2 * x + 8;
plot(x, y);
@a-gu
a-gu / TidBITS.tsv
Created November 8, 2017 16:30
TidBITS AutoCorrect dictionary
aand and
abilites abilities
abilitiy ability
abilties abilities
abiltities abilities
abiltiy ability
abilty ability
abitlities abilities
ablity ability
abloished abolished
@a-gu
a-gu / cattermark.bat
Last active November 27, 2017 04:16
Adds random watermarks on top of images with ImageMagick
@echo off
REM Adds random watermarks on top of images with ImageMagick
REM Used cat images from DuckDuckGo, thus the program name
REM Needs the following folders to be in the working directory:
REM "input" Input images to watermark
REM "output" Empty directory for watermarked images
REM "watermark" Images to overlay