Skip to content

Instantly share code, notes, and snippets.

View tech-podcast-ja.mkd
View chrome_throttle.cpp
#include "brt.h"
#include <windows.h>
#include <psapi.h>
struct WorkingSetParams {
HANDLE process_handle;
size_t min_working_set;
size_t max_working_set;
DWORD flags;
@ACEfanatic02
ACEfanatic02 / rust_shell.ps1
Created Oct 30, 2014
Powershell script to sanitize $ENV:PATH so that existing MinGW install doesn't interfere with Rust.
View rust_shell.ps1
$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
}
}
View cfg_parser.cpp
// 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 / markov.py
Last active Aug 29, 2015
Simple Markov chain generator. Based partially on: https://golang.org/doc/codewalk/markov/
View markov.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
from collections import defaultdict
class MarkovPrefix(object):
def __init__(self, n):
if n < 1:
@ACEfanatic02
ACEfanatic02 / tokenize.c
Created Sep 2, 2014
A different take on strtok_r.
View tokenize.c
#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) {
View QuadTree.cpp
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 / DoubleBufferedMap.cpp
Created May 20, 2014
Class to encapsulate a double-buffered 'map' (2d array). Write to mutable back buffer, render from constant front buffer. After updating, switch the buffers.
View DoubleBufferedMap.cpp
template<typename T>
class DoubleBufferedMap
{
private:
size_t m_width;
size_t m_height;
T * m_front;
T * m_back;
public:
@ACEfanatic02
ACEfanatic02 / elevator.py
Created May 7, 2014
Playing with elevator scheduling.
View elevator.py
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)
View rspec_rails_cheetsheet.rb
#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)