Skip to content

Instantly share code, notes, and snippets.

View ZwodahS's full-sized avatar

Eric ZwodahS

View GitHub Profile
@ZwodahS
ZwodahS / replaceString
Created May 29, 2014 09:14
A simple find and replace for C++
std::string& replaceString(std::string& newString, const std::string& searchString, const std::string& replaceString, const bool& multipleReplace)
{
size_t index = newString.find(searchString);
if(multipleReplace)
{
while(index != std::string::npos)
{
// replace
newString.replace(index, searchString.size(), replaceString);
// start searching from the end of the replaceString, such that the replaceString will never be part of the search
def generate_maze(x, y, config={}):
structure = []
for i in range(x):
l = []
for j in range(y):
l.append(6)
structure.append(l)
maze = {
"x" : x,
@ZwodahS
ZwodahS / string_format.cpp
Last active August 29, 2015 14:06
C++ simple string formating
/*
* DO WHAT THE F*** YOU WANT TO PUBLIC LICENSE
* Version 2, December 2004
*
* Copyright (C) 2013- ZwodahS(ericnjf@gmail.com)
* zwodahs.github.io
*
* Everyone is permitted to copy and distribute verbatim or modified
* copies of this license document, and changing it is allowed as long
* as the name is changed.
@ZwodahS
ZwodahS / dict_utils.py
Last active August 29, 2015 14:11
filters dictionary in python.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# Author : Eric (github.com/ZwodahS)
# License : Public Domain
"""
data_matrix.py
Author: Eric
github: ZwodahS
data_matrix is a simple modules that helps you count on a N-dimension matrix.
terminology:
" DO WHAT THE **** YOU WANT TO PUBLIC LICENSE
" Version 2, December 2004
"
" Copyright (C) 2013 ZwodahS(ericnjf@gmail.com)
" zwodahs.wordpress.com
"
" Everyone is permitted to copy and distribute verbatim or modified
" copies of this license document, and changing it is allowed as long
" as the name is changed.
"
@ZwodahS
ZwodahS / gist:6638137
Created September 20, 2013 14:09
git branch display and coloring of path in terminal
c_cyan=`tput setaf 6`
c_red=`tput setaf 1`
c_green=`tput setaf 2`
c_sgr0=`tput sgr0`
parse_git_branch ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
gitver=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
#!/bin/bash
# git + ls
C_RED=$(tput setaf 1)
C_GREEN=$(tput setaf 2)
C_YELLOW=$(tput setaf 3)
C_BLUE=$(tput setaf 4)
C_MAGENTA=$(tput setaf 5)
C_CYAN=$(tput setaf 6)
C_WHITE=$(tput setaf 7)
C_CLEAR=$(tput sgr0)
@ZwodahS
ZwodahS / quad_tree.py
Created June 14, 2016 14:29
Simple quad tree for searching points inside polygon
import json
from shapely.geometry.polygon import Polygon
from shapely.geometry import Point, box as Box
class _Quad(object):
def __init__(self, quad_tree, parent):
self.quad_tree = quad_tree
@ZwodahS
ZwodahS / options_parser.py
Last active February 16, 2017 09:28
A better options_parser for tornado
import os
import sys
import logging
from tornado.options import OptionParser, Error
def define_config_file_settings(parser, option_name="config_file"):
parser.define(option_name, type=str, help="config file to load",
callback=lambda path:parser.parse_config_file(path, fail_silently=True, final=False))