Skip to content

Instantly share code, notes, and snippets.

View theddaywork's full-sized avatar
🏠
Working from home

David theddaywork

🏠
Working from home
View GitHub Profile
@illy
illy / sed and awk notes.md
Created July 31, 2012 22:15
sed and awk notes

##AWK notes##

  1. selective printing

     awk '$2 ~ regex, { $1="", pring $0}' 
    

If $2 = regex, then print the whole line but not $1

  1. convert a single line to multiple lines
@pamelafox
pamelafox / geonames.py
Created April 3, 2012 00:22
Geonames Python wrapper
import sys
import urllib
import urllib2
import json
import logging
class GeonamesError(Exception):
def __init__(self, status):
@aaltat
aaltat / py_finder.py
Last active March 2, 2020 00:03
Find files which are not Python 3 compatible
import argparse
import subprocess
from pathlib import Path
def find_files(src_root: Path, python3: Path):
not_py3_compatible = []
for file in src_root.rglob('*.py'):
print(file.resolve())
@siddhi
siddhi / pyconindia_dsl.py
Created September 16, 2011 06:33
Domain Specific Languages in Python - Pycon India - 17 Sep 2011
from pyparsing import *
# By default, PyParsing treats \n as whitespace and ignores it
# In our grammer, \n is significant, so tell PyParsing not to ignore it
ParserElement.setDefaultWhitespaceChars(" \t")
def parse(input_string):
def convert_prop_to_dict(tokens):
"""Convert a list of field property tokens to a dict"""
prop_dict = {}
@Musinux
Musinux / install-packages.sh
Last active March 29, 2021 12:49
VNC xstartup for unity WARNING ! THIS WAS WRITTEN A LONG TIME AGO (2018), IT MAY NOT BE RELEVANT ANYMORE
#!/bin/bash
# WARNING ! THIS WAS WRITTEN A LONG TIME AGO (2018), IT MAY NOT BE RELEVANT ANYMORE
sudo apt-get install vnc4server ubuntu-desktop
sudo apt-get install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal
@Tset-Noitamotua
Tset-Noitamotua / triple_run_tests.bat
Last active April 9, 2021 18:41
Batch script to rerun failed Robot Framework tests on a Windows machine for a (almost) fail save test execution ;-)
@ECHO OFF
REM Activate required Python v-environment for test execution
REM Uncomment next line and adjust NAME if you use "virtualenv"
REM and "virtualenvwrapper-win"
REM call workon NAME_OF_YOUR_VIRTUALENV
REM Clean up Results folder before you start!
REM /Q options ensures that no confirmation by user is required
REM Uncomment next line if you use a "Results" folder
@rodrigogiraoserrao
rodrigogiraoserrao / ocalc.py
Last active July 13, 2021 12:16
One-expression calculator.
# A Tkinter calculator in a single Python *expression*
# See https://www.reddit.com/r/Python/comments/ojab0n/i_see_your_17_loc_calculator_and_i_raise_you_a/
(tk := __import__("tkinter")) and (bt_draw := lambda k, c, l: (bt := tk.Button(w, text=k, command=lambda: bt_press(k), width=6)) and bt.grid(column=c, row=l)) and (update := lambda t: d.config(text=t)) and (bt_press := lambda k: update("") if k == "C" else update(d["text"][:-1]) if k == "<" else update(str(round(eval(d["text"]), 6))) if k == "=" else update(d["text"] + k)) and (w := tk.Tk()) and w.title("TKalc") or (d := tk.Label(w, text="")) and d.grid(column=0, row=0, columnspan=5) or [bt_draw(k, n%4 + 1, n//4 + 1) for n, k in enumerate("()C<789/456*123-.0=+")] and w.mainloop()
@mkorpela
mkorpela / find_unused.py
Created January 20, 2012 11:57
Finding unused Robot Framework user keywords
import sys
from robotide.controller.chiefcontroller import ChiefController
from robotide.controller.commands import NullObserver
from robotide.controller.filecontrollers import DirectoryController
from robotide.namespace import Namespace
from robotide.spec.iteminfo import LibraryKeywordInfo
from robotide.usages.commands import FindUsages
def construct_chief_controller(datapath):
@hwayne
hwayne / queue_template.py
Created November 2, 2020 02:47
Code for PRISM essay
from math import comb
from string import Template
guard = "[worker] (left >= {n} & ((queue >= {n} & K = {n}) | (queue = {n} & K > {n}))) ->"
# For n = 3, this should be
# p^3 + 3p^2(1-p) + 3p(1-p)^2 + (1-p)^3
def actions_for(n):
base = "{prob}: (left' = left - {x}) & (queue' = queue - {x})"
@0xadada
0xadada / README.md
Last active August 5, 2022 16:48
VIM movement, keyboard commands and shortcuts