Skip to content

Instantly share code, notes, and snippets.

View hardik-vala's full-sized avatar

Hardik hardik-vala

  • San Francisco Bay Area
View GitHub Profile
@hardik-vala
hardik-vala / modify-html-text.js
Last active August 29, 2015 14:26
Modify text on an HTML page using just Javascript.
// HTML source under body tag.
var originalContent = document.body.innerHTML || document.body.textContent;
// Split the content on tags, keeping the tags.
var splitOriginalContent = originalContent.split(/(<[^>]*>)/g);
var parsedTextList = [], inScript = false, inStyle = false;
for (var i = 0, len = splitOriginalContent.length; i < len; i++) {
// Skip script tags and content.
if (splitOriginalContent[i].startsWith('<script'))
@hardik-vala
hardik-vala / strip_quotes.py
Created October 9, 2015 20:41
Python script for stripping the quotes (i.e. dialogue) from a novel text (where the quote markers are heuristically determined).
# -*- coding: UTF-8 -*-
"""
Strips the quotes from a novel text.
@author: Hardik
"""
import argparse
import logging
@hardik-vala
hardik-vala / .gitconfig
Last active November 17, 2015 22:15
My simple .gitconfig
[core]
editor = vim
[alias]
aa = add --all
co = checkout
cm = commit
cmm = commit -m
cmam = commit -a -m
recm = commit --amend -m
st = status
@hardik-vala
hardik-vala / quine.c
Last active December 25, 2015 21:27
A real simple quine in C.
#include <stdio.h>
char* s = "#include <stdio.h>%c%cchar* s = %c%s%c;%c%cint main() {%c%cprintf(s,10,10,34,s,34,10,10,10,9,10,9,10,10,10,10,10,10,10,10,10,10,10);%c%creturn 0;%c}%c";
int main() {
printf(s,10,10,34,s,34,10,10,10,9,10,9,10,10,10,10,10,10,10,10,10,10,10);
return 0;
}
@hardik-vala
hardik-vala / dualboot.md
Last active December 28, 2020 10:26
How dual-boot Windows 7 with Mac OS X

How to dual-boot Windows 7 with Mac OS X

Seemingly simple, but couldn't get any of Google-able methods to work with my Macbook Pro. So I've pieced together a solution that works on Yosemite (Mac OS 10.10).

  1. Grab an .iso image of Windows 7 (The Internet has plenty of ways of doing this)

  2. Create a USB Installer from it (An easy Google)

@hardik-vala
hardik-vala / .tcshrc
Last active March 2, 2016 05:15
A semi-template for a .tcshrc
# Change default permissions for file and directory creation to allow group read, writes, and execution.
umask 002
# Include local bin directory in path.
setenv PATH ${PATH}:${HOME}/bin/
# Activate Python virtual environment.
source ~/venv/bin/activate.csh
# Set-up prompt.
@hardik-vala
hardik-vala / brat-prelabel.py
Created March 2, 2016 03:36
A script for pre-labelling mentions in a text with some entity tag, outputting the labelings in brat's .ann format.
"""
Pre-labels spans in text with a particular entity tag according to a span
list. Takes as input a raw text file and outputs a brat .ann file with
the pre-labelled info.
@author: Hardik
"""
import argparse
import os
@hardik-vala
hardik-vala / build.sbt
Created March 7, 2016 03:59
Adding Stanford CoreNLP to build.sbt
name := "myproject"
version := "1.0"
libraryDependencies ++= Seq(
"edu.stanford.nlp" % "stanford-corenlp" % "3.6.0",
"edu.stanford.nlp" % "stanford-corenlp" % "3.6.0" classifier "models"
)
@hardik-vala
hardik-vala / sms-decorator.py
Created May 1, 2016 04:42
Example illustrating how to use a decorator to notify you via text message if a long running function crashes.
"""
Example illustrating how to use a decorator to notify you via text message if a
long running function crashes.
"""
import os
import time
# Phone number (You may want to change this).
@hardik-vala
hardik-vala / universal_exception_handler.js
Created May 5, 2016 03:05
The one Javascript exception handler to rule them all.
/* I did not come up this but can't find the proper source. */
try {
// Some shiz.
} catch (e) {
var xcb="http://stackoverflow.com/search?q=[js]" + e.message;
window.open(xcb, '_blank');
}