Skip to content

Instantly share code, notes, and snippets.

@bootandy
bootandy / tokenizer2.rs
Created January 16, 2018 23:45
rust: better tokenizer
fn update_state<'a>(s :&'a str, tokens :&mut Vec<String>, match_point : &Captures<'a>) -> &'a str {
let new_s = &s[match_point.get(1).unwrap().end()..];
tokens.push(match_point.get(1).unwrap().as_str().to_string());
new_s
}
pub fn tokenizer(s_in: &str) -> Reader {
let mut s = &s_in[0..];
let brackets = regex!(r###"^[\s,]*([\(\)\{\}\[\]])[\s,]*"###);
@bootandy
bootandy / tic_tac_toe.py
Created July 6, 2017 21:40
Simple Os and Xs game
from __future__ import absolute_import, division, print_function
import random
import copy
EMPTY = '_'
def winner(spaces):
winning_tile = filter(lambda a:a, [_is_row_winner(row) for row in spaces])
@bootandy
bootandy / dfs.py
Created July 6, 2017 21:05
Simple depth first search
from __future__ import absolute_import, division, print_function
class Node(object):
def __init__(self, value, parent, left=None, right=None):
self.right = right
self.left = left
self.parent = parent
self.value = value
@bootandy
bootandy / .vimrc
Last active February 25, 2018 23:31
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required :PluginInstall
Plugin 'VundleVim/Vundle.vim' "This package manager
Plugin 'tpope/vim-fugitive'
@bootandy
bootandy / simple_turtle_puzzle.py
Last active April 28, 2016 10:12
simple_turtle_puzzle.py
# This task is meant to simulate tiling a wall.
# It uses Turtle also known as Logo.
# Turtle instructions
# https://docs.python.org/2/library/turtle.html
# Sample code:
import turtle
@bootandy
bootandy / .zshrc
Last active November 6, 2019 09:22
.zshrc file uses oh-my-zsh
# Path to your oh-my-zsh installation.
export ZSH="/home/andy/.oh-my-zsh"
alias python=python3
# time that oh-my-zsh is loaded.
ZSH_THEME="tjkirch"
# Plugins zsh-syntax-highlightin is downloaded separately
plugins=(git python zsh-syntax-highlighting)
@bootandy
bootandy / bash_aliases.sh
Created August 12, 2015 09:55
basic bash script to drop on a new box
# colors
export CLICOLOR=1
export TERM=xterm-color
export LSCOLORS=gxgxcxdxbxegedabagacad # cyan directories
#Giant history
export HISTSIZE=99999
# set - same as _
set completion-map-case on
@bootandy
bootandy / simple_puzzles.txt
Last active April 27, 2016 13:12
Ideas for simple programming puzzles
Simple:
2 people get married - adjust names, also double barrelled names
Replace word X with word Y
Normal:
Reverse String
Reverse words in String
@bootandy
bootandy / profile_jinja.py
Created November 6, 2014 00:09
How 2 line_profiler test a jinja2 template
import os
from jinja2 import Environment, FileSystemLoader
from line_profiler import LineProfiler
@profile
def render_template(template_filename, context):
return TEMPLATE_ENVIRONMENT.get_template(template_filename).render(context)
PATH = os.path.dirname(os.path.abspath(__file__))
class RemoveWWW(object):
def process_request( self, request ):
try:
if request.META['HTTP_HOST'].lower().find('www.') == 0:
from django.http import HttpResponsePermanentRedirect
return HttpResponsePermanentRedirect( request.build_absolute_uri().replace('//www.', '//') )
except:
pass
return None