Skip to content

Instantly share code, notes, and snippets.

View hippietrail's full-sized avatar

Andrew Dunbar hippietrail

  • Phong Nha
  • 19:14 (UTC +07:00)
View GitHub Profile
@hippietrail
hippietrail / se-add-search-result.js
Created October 18, 2012 17:19
Add a new entry to Stack Exchange search results
$('<div>', {
class: 'question-summary',
id: 'question-summary-QID',
html: $('<div>', {
class: 'statscontainer',
html: $('<div>', {
class: 'statsarrow'
})
}).append($('<div>', {
class: 'stats',
@hippietrail
hippietrail / google-search-se-questions.js
Created October 18, 2012 17:26
Get Stack Exchange question IDs from Google Search results
$('a.l').map(function(i, e) {
return !e.search ? e.href : (function(s) {
var u = '?';
s.split('&').forEach(function(ee, ii) {
var e = ee.split('=');
if (e[0] == 'url')
u = e[1];
});
return decodeURIComponent(u);
})(e.search);
@hippietrail
hippietrail / se-sort-tags-by-relevance.js
Created October 19, 2012 06:24
Sort Stack Exchange tags by relevance
var $c = $('#h-related-tags').parent().contents(),
s = null,
arr = [];
$c.each(function(i, e) {
var $sl, counts;
if (e.tagName === 'A') {
s = i;
} else if (e.tagName == 'BR') {
@hippietrail
hippietrail / ht-se-search-google.user.js
Created December 2, 2012 04:08
Convert a search on a StackExchange site to a Google search of that site
// ==UserScript==
// @name Hippietrail's StackExchange search to Google search
// @description Convert a search on a StackExchange site to a Google search of that site
// @version 0.0
// @namespace hippietrail
// @include http://stackoverflow.com/search*
// @include http://meta.stackoverflow.com/search*
// @include http://serverfault.com/search*
// @include http://meta.serverfault.com/search*
// @include http://superuser.com/search*
@hippietrail
hippietrail / linebyline.js
Created January 5, 2013 11:40
My attempt at the minimal code to read text files one line at a time in node.js
var fs = require('fs'),
StringDecoder = require('string_decoder').StringDecoder,
util = require('util');
function lineByLine(fd) {
var blob = '';
var blobStart = 0;
var blobEnd = 0;
var decoder = new StringDecoder('utf8');
@hippietrail
hippietrail / stripgutenberg.pl
Created December 22, 2010 18:59
Strip headers/footers from Project Gutenberg texts
#!/usr/bin/perl
# stripgutenberg.pl < in.txt > out.txt
#
# designed for piping
# Written by Andrew Dunbar (hippietrail), released into the public domain, Dec 2010
use strict;
my $debug = 0;
@hippietrail
hippietrail / fetch-wikipedia-text.swift
Created March 17, 2024 18:12
Swift code to fetch one or more English Wikipedia articles as plain text without most of the interface text
import Foundation
/// Executes two commands in a pipeline.
///
/// - Parameters:
/// - firstCommand: The first command to execute. This should be a valid
/// command that you would type into the terminal.
/// - secondCommand: The second command to execute. This should be a valid
/// command that you would type into the terminal.
/// - args: The command line arguments passed to the script.
@hippietrail
hippietrail / fetch-youtube-transcript.ts
Last active March 17, 2024 18:13
TypeScript code to fetch one or more YouTube transcripts as plain text without API key
import url from 'url';
interface Cue {
transcriptCueRenderer: {
cue: {
simpleText: string;
};
};
}
@hippietrail
hippietrail / custom_fprintf.c
Last active March 23, 2024 19:38
Example of how to wrap C printf type functions to add a new format specifier
// adds the %hb specifer to print a number of bytes in human-readable number of bytes/kb/mb
// there's no way to modify or build a va_list after handling some of them ourselves
// so we get the standard function to ignore them by treating them as zero-length strings
// this could be a problem for compilers that evaluate a number as a string pointer before truncating
// but it works with clang on Xcode 15.3
// there's no buffer overflow handling to make the code easy to follow - don't deploy as-is in real code!
void custom_fprintf(FILE* stream, const char* format_orig, ...) {
size_t format_orig_len = strlen(format_orig);
va_list args_orig, args_copy;