Skip to content

Instantly share code, notes, and snippets.

require 'net/http'
require 'rubygems'
require 'json'
require 'nokogiri'
require 'fileutils'
require 'fastimage'
require 'ruby-debug'
# ruby ntags.rb output_directory event_id -f format_storage_file
# ruby ntags.rb -e format_storage_file nametag_p1 nametag_p2 ...
@xiagu
xiagu / kittens_helpers.js
Last active November 29, 2021 06:49
Quick scripts to help play kittens game because life is short
SECONDS = 1e3;
MINUTES = 60 * SECONDS;
HOURS = 60 * MINUTES;
VERBOSE_AUTO = true;
autocraftNames = ['steel', 'plate'];
mediumCraftNames = ['kerosene', 'thorium', 'eludium'];
slowCraftNames = ['beam', 'slab', 'parchment', 'manuscript'];
scienceCraftNames = ['parchment', 'manuscript', 'compendium'];
religionBuyNames = ['Black Pyramid', 'Black Nexus', 'Black Core'];
@xiagu
xiagu / junk.js
Created December 4, 2016 00:02
convert equatorial/celestial coodinates to horizontal coordinates
Date.prototype.isLeapYear = function() {
var year = this.getFullYear();
if((year & 3) != 0) return false;
return ((year % 100) != 0 || (year % 400) == 0);
};
// Get Day of Year
Date.prototype.getDOY = function() {
var dayCount = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
@xiagu
xiagu / gui-completion.c
Created April 26, 2016 21:26
A snippet containing a small edge case bug.
index2 = (completion->direction < 0) ? index - 1 : index + 1;
while ((index2 >= 0) && (index2 < completion->list->size))
{
ptr_completion_word2 =
(struct t_gui_completion_word *)(completion->list->data[index2]);
if ((ptr_completion_word->nick_completion
&& (gui_completion_nickncmp (completion->base_word,
ptr_completion_word2->word,
length) == 0))
|| (!ptr_completion_word->nick_completion
@xiagu
xiagu / gui-completion.c
Created April 26, 2016 19:13
Snippet from Weechat's gui-completion.c. I feel like this could be rewritten with memcpy...
if (pos_start <= pos_end)
{
completion->position_replace = pos_start;
completion->base_word = malloc (pos_end - pos_start + 2);
for (i = pos_start; i <= pos_end; i++)
{
completion->base_word[i - pos_start] = data[i];
}
completion->base_word[pos_end - pos_start + 1] = '\0';
}
@xiagu
xiagu / World.java
Created March 4, 2016 18:25
Part of a 3D tower defense game I made... in 2008
import java.awt.event.*;
import java.awt.image.*;
import java.text.NumberFormat;
import java.awt.*;
import java.io.*;
import java.util.*;
import java.nio.*;
import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import javax.swing.*;
@xiagu
xiagu / autocomplete.directive.js
Created March 3, 2016 16:27
Terrible workaround for weird select2 bug
// For some reason select2 interferes with the space key for multiple
// selects. It doesn't in its own examples, but it does here. This is a
// workaround to manually add a space to the input. It uses JQuery event
// delegation because the actual element that the event is triggered on
// doesn't exist at the time this gets set up.
element.parent().on('keypress', '.select2-selection', awfulSpaceHack);
element.on('$destroy', function () {
element.parent().off('keypress', '.select2-selection', awfulSpaceHack);
});
function awfulSpaceHack(evt) {
@xiagu
xiagu / reflog
Created March 1, 2016 18:42
leaving a commit behind
7ae0ae7 HEAD@{0}: checkout: moving from d3db4a7d4eb3394286e0ca815edc5c66d5b45120 to master
d3db4a7 HEAD@{1}: commit: Another boop
3ff7027 HEAD@{2}: checkout: moving from master to 3ff7027
7ae0ae7 HEAD@{3}: commit: Boop
3ff7027 HEAD@{4}: clone: from https://github.com/xiagu/2015-advent-of-code.git
@xiagu
xiagu / rp_tags.rb
Created February 5, 2016 18:19
Alternate Tag#<=> implementation
##
# Compares two tags. Character tags are less than meta tags, and meta
# tags are less than general tags. Two tags of the same type are compared
# by their names.
def <=>(other)
sort_order = [:character, :meta, :general]
arr = [""] * 3
other_arr = [""] * 3
# Due to quirks, the string <=> behavior vs "" is the opposite of what
# we want for comparing names. "" is the 'smallest' string. Everything
@xiagu
xiagu / tree output.txt
Created January 24, 2016 01:00
The generated site scaffold for a new Jekyll::RpLogs site
.
├── arcs.html
├── _config.yml
├── _config.yml.default
├── css/
│   └── main.scss*
├── Gemfile
├── Gemfile.lock
├── _includes/
│   ├── footer.html