Skip to content

Instantly share code, notes, and snippets.

@odedlaz
odedlaz / coroutine_pipe.py
Created April 11, 2017 16:25
Full gist of my blog post about piping with coroutines
from __future__ import print_function
from functools import wraps
from io import SEEK_END
from re import compile
from sys import argv
from time import sleep
RE_TYPE = type(compile(""))
@odedlaz
odedlaz / ds_intro_lab1_solution.sh
Created April 2, 2017 09:18
ds_intro_lab1_solution.sh
#!/usr/bin/env bash
filename="$1"
# solution using bash
count=0
while read -r line
do
if echo "$line" | grep "CHAPTER" > /dev/null; then
((count++))

Keybase proof

I hereby claim:

  • I am odedlaz on github.
  • I am odedlaz (https://keybase.io/odedlaz) on keybase.
  • I have a public key ASAU1lUk2Ot0OhWdA-AB6YzuAJKxIXTvwesw-v6GAZ1rlAo

To claim this, I am signing this object:

@odedlaz
odedlaz / update-nvim-python-client.zsh
Last active January 30, 2017 14:08
A script that updated neovim python packages
#!/usr/bin/zsh
function update_python_packages {
USERNAME=$(logname)
# run command as the user who logged in. see: https://goo.gl/akX2eo
echo "Updating neovim python$1 libraries ..."
source /opt/nvim/python$1/bin/activate
pip install -u --upgrade pip &> /dev/null
packages_to_install=$(pip list --outdated --format=legacy)
@odedlaz
odedlaz / getenv_idiom.py
Last active January 20, 2017 15:23
os.getenv idiom
import os
def getenv(varname, default=None, typecast_fn=None):
"""
Return the value of the environment variable varname if it exists, or default if it doesn't.
default defaults to None.
:typecast_fn: a function that performs the typecast. if not supplied, defaults to type(value)
"""
@odedlaz
odedlaz / ocr.py
Last active February 4, 2017 22:04
OCR using tesserocr
from tesserocr import PyTessBaseAPI
import sys
import os
# tesserocr -> https://pypi.python.org/pypi/tesserocr
# cython -> https://pypi.python.org/pypi/Cython
# Pillow -> https://pypi.python.org/pypi/Pillow
if len(sys.argv) != 2:
print("you need to pass the path to the image as first argument")
@odedlaz
odedlaz / less_syntax_highlight.sh
Last active December 25, 2016 21:06
less_syntax_highlight
# The following adds syntax highlighting to various programming languages
# Credit goes to Ter Smitten: https://goo.gl/64YU4u
export LESSOPEN="| /usr/share/source-highlight/src-hilite-lesspipe.sh %s"
export LESS=' -R '
# The following adds syntax highlighting to man pages
# Credit goes to Todd Weed: https://goo.gl/ZSbwZI
export LESS_TERMCAP_mb=$'\e[01;31m' # begin blinking
export LESS_TERMCAP_md=$'\e[01;38;5;74m' # begin bold
export LESS_TERMCAP_me=$'\e[0m' # end mode
@odedlaz
odedlaz / python_36_statements_whole_code.py
Last active December 6, 2016 10:14
python_36_statements_whole_code.py
from __future__ import print_function
import os
import sys
import six
from time import time
from random import choice
from types import CodeType, FunctionType
from functools import wraps
from string import Formatter
@odedlaz
odedlaz / python_36_print.py
Created December 6, 2016 09:12
python_36_print.py
name = "oded"
age = 26
print("My name is: {name}, my age is: {age} and 2*3={2*3}!")
# My name is oded, my age is: 26 and 2*3=6!
@odedlaz
odedlaz / fast_local_compiled_print.py
Created December 6, 2016 09:01
fast_local_compiled_print.py
def awesome_print(text, **kwargs):
text = "a format with {GENERATED_NAME} and {ANOTHER_GENERATED_NAME}"
std_print(text.format(GENERATED_NAME=(STATEMENT), ANOTHER_GENERATED_NAME=(ANOTHER_STATEMENT), **kwargs))