Skip to content

Instantly share code, notes, and snippets.

@ACEfanatic02
ACEfanatic02 / grepword.rb
Last active August 29, 2015 13:57
Simple grep for word in a directory of textfiles. Work in progress...
#!/usr/bin/env ruby
# Change SEARCH_ROOT to point to proper directory.
# USAGE: ruby grepword.rb <word>
SEARCH_ROOT = "/path/to/books/directory"
word = Regexp.new(ARGV[0].encode('utf-8', 'external'))
def clean line
@ACEfanatic02
ACEfanatic02 / load-dialog.js
Created April 9, 2014 03:14
Loading dialog content via ajax.
$(document).ready(function() {
var schedule_dialog = $("#appt-dialog")
schedule_dialog.dialog({
autoOpen: false,
modal: true,
minWidth: 600,
minHeight: 200
});
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@ACEfanatic02
ACEfanatic02 / elevator.py
Created May 7, 2014 04:21
Playing with elevator scheduling.
class ElevatorRequest(object):
def __init__(self, from_floor, to_floor):
self.from_floor = from_floor
self.to_floor = to_floor
def __cmp__(self, other):
return self.from_floor == other.from_floor
def __str__(self):
return "<ElevatorRequest: From %d to %d>" % (self.from_floor, self.to_floor)
@ACEfanatic02
ACEfanatic02 / DoubleBufferedMap.cpp
Created May 20, 2014 15:25
Class to encapsulate a double-buffered 'map' (2d array). Write to mutable back buffer, render from constant front buffer. After updating, switch the buffers.
template<typename T>
class DoubleBufferedMap
{
private:
size_t m_width;
size_t m_height;
T * m_front;
T * m_back;
public:
class QuadTree
{
private:
static const int MAX_ENTITIES = 20;
std::vector<Entity *> m_entities;
sf::Vector2i m_position;
sf::Vector2i m_size;
QuadTree * m_nodes;
int getIndex(const Entity * e) const
@ACEfanatic02
ACEfanatic02 / tokenize.c
Created September 2, 2014 22:17
A different take on strtok_r.
#include <stdlib.h>
#include <stdio.h>
typedef struct tokenize_state_t {
const char * position;
} tokenize_state_t;
int check_delim(char c, const char * delim) {
for (const char * cur = delim; *cur != '\0'; ++cur) {
if (c == *cur) {
@ACEfanatic02
ACEfanatic02 / markov.py
Last active August 29, 2015 14:06
Simple Markov chain generator. Based partially on: https://golang.org/doc/codewalk/markov/
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
from collections import defaultdict
class MarkovPrefix(object):
def __init__(self, n):
if n < 1:
// File format:
//
// Roughly based on INI style configs.
//
// 'Key=Value' pairs, one pair per line. If a line contains more than one '=',
// the first is taken to be the deliminator and the rest are included as part
// of the value string.
//
// A line containing a key but no value (i.e., no '='), will be parsed as an
// entry with an empty value string.
@ACEfanatic02
ACEfanatic02 / rust_shell.ps1
Created October 30, 2014 04:51
Powershell script to sanitize $ENV:PATH so that existing MinGW install doesn't interfere with Rust.
$mingwPath = "C:\MinGW\bin" # Replace with MinGW path from $ENV:PATH
$pathArray = $ENV:PATH.Split(";")
$newPath = ""
Foreach ($p in $pathArray) {
if (!$p.Equals($mingwPath)) {
$newPath += ";"
$newPath += $p
}
}