Skip to content

Instantly share code, notes, and snippets.

View ZwodahS's full-sized avatar

Eric ZwodahS

View GitHub Profile
" 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')
@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
@ZwodahS
ZwodahS / Curse cheatsheet
Created June 12, 2014 17:26
Curse cheatsheet (ncurses, pdcurses etc)
//// General stuffs ////
initscr(); // "start curses"
endwin() ; // "end curses"
//// Windowing ////
WINDOW* window = newwin(height, width, startY, startX)
//// Draw ///
refresh()
wrefresh(window)
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:
@ZwodahS
ZwodahS / copy_redis_key.sh
Created March 1, 2016 06:07
copy a redis db key to another place (use MIGRATE COPY for v3.0<= redis)
#!/bin/bash
# source http://stackoverflow.com/questions/23222616/copy-all-keys-from-one-db-to-another-in-redis
#set connection data accordingly
source_host=localhost
source_port=6379
source_db=1
target_host=localhost
target_port=6379
target_db=2
#!/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)