Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
/* bit logic experiment */
int main(int argc, char *argv[])
{
int x, y = 0;
char input = '\0';
printf("Enter first digit: ");
@ACEfanatic02
ACEfanatic02 / _go2function.py
Created August 31, 2012 01:46
edited find to use regex
#actually do the grep
#well, actually use the native python functions, not grep...
def doGrep(self, word, directory):
out = ()
for r,d,f in os.walk(directory):
#don't bother to look in git dirs
if ".git" not in r:
for files in f:
@ACEfanatic02
ACEfanatic02 / gist:3903520
Created October 17, 2012 03:18
aozora parser -- mark pages
def _mark_pages(self, text):
"""
Inserts comments in %text to mark the end of pages. Differs from BDH's
in that it breaks only at newlines or punctuation for a clean result.
"""
# Regex ripped wholesale from BDH.
to_skip = re.compile(ur"""((-------------------------------------------------------.*?-------------------------------------------------------)|(|)|([#.*?])|(《.*?》)|(<.*?>)|(\n)|(\s))+""", re.UNICODE | re.S)
skipped = []
for match in to_skip.finditer(text):
@ACEfanatic02
ACEfanatic02 / rubylizer.py
Created October 23, 2012 03:21
aozora parser - ruby and bouten, bouten = broken
# -*- coding: utf-8 -*-
import re
""" Rubylizer
Module for preparing rubytext tags from the furigana marked in
青空文庫-formatted text.
"""
def contains(self, value):
""" contains
Searchs recursively for a node containing the given value from current
node. Returns True on success and False on failure.
Args:
value: the value being searched for in the tree.
"""
def _contains(value, current):
# -*- coding: utf-8 -*-
import ast
RE_EXPR = re.compile(ur"\((\d+\.?\d*\s?[+-]\s?\d+\.?\d*)\)")
RE_TIME = re.compile(ur"(\d{2}):(\d{2}):(\d{2})")
def parse_value(string, entry_type):
"""Parses an input value to floating point. Allows expressions
of the form `(XX.X[+-]XX.X)` or `XX:XX:XX` as special cases, otherwise
def get_entry_type(self):
"""Returns selected entry type as string key."""
radio_pairs = [(self.window.ui.book_radio, 'book'),
(self.window.ui.manga_radio, 'manga'),
(self.window.ui.game_radio, 'game'),
(self.window.ui.flgame_radio, 'fullgame'),
(self.window.ui.net_radio, 'net'),
(self.window.ui.news_radio, 'news'),
(self.window.ui.nico_radio, 'nico'),
(self.window.ui.subs_radio, 'subs'),
@ACEfanatic02
ACEfanatic02 / 4241.c
Last active December 16, 2015 23:49
4241 CPU emulator, in C.
// 4241 4-bit Microprocessor
//
// Registers: r0 r1
//
// 1-byte Instructions
// 0 = Halt
// 1 = Add (r0 = r0 + r1)
// 2 = Subtract (r0 = r0 - r1)
// 3 = Increment r0
// 4 = Increment r1
@ACEfanatic02
ACEfanatic02 / gist:5824884
Created June 20, 2013 17:40
normalize_kana
# -*- coding: utf-8 -*-
FULL_KATA_OFFSET = ord(u"ァ") - ord(u"ぁ")
half_kata_to_hira = u"をぁぃぅぇぉゃゅょっーあいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよ"
def normalize_kana(s):
"""Normalizes all kana in the given string to full-width hiragana.
Args:
s String to be normalized.
@ACEfanatic02
ACEfanatic02 / utf8count.c
Created August 14, 2013 00:59
Count number of actual characters in a utf8 bytestring.
#include <stdint.h>
#include <stdbool.h>
typedef unsigned char uchar8_t;
static bool is_leading_byte(const uchar8_t c)
{
return (c <= 0x7f || c >= 0xc2);
}