Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
KIAaze committed Jan 13, 2016
2 parents 538d230 + 386fad7 commit b025b63
Show file tree
Hide file tree
Showing 22 changed files with 1,341 additions and 103 deletions.
52 changes: 52 additions & 0 deletions bins/public_bin/bucky_ball.py
@@ -0,0 +1,52 @@
#!/usr/bin/env python3

def check(v, e, f, p, h, verbose=True):
if verbose:
print('v={}, e={}, f={}, p={}, h={}'.format(v,e,f,p,h))
c_0 = (5*p+6*h == 2*e)
c_1 = (p+h == f)
c_2 = (v-e+f == 2)
c_all = c_0 and c_1 and c_2
if verbose:
print(c_0, c_1, c_2, c_all)
return c_all

def calc_p_h(v, e, f):
print(v,e,f)
for p in range(0, f+1):
h = f - p
if check(v, e, f, p, h, verbose=False):
check(v, e, f, p, h, verbose=True)

print('== c60 ==')
v=60
e=90
f=32
calc_p_h(v, e, f)
p=12
h=20
check(v, e, f, p, h, verbose=True)

print('== c70 ==')
v=70
e=105
f=37
calc_p_h(v, e, f)
p=12
h=25
check(v, e, f, p, h, verbose=True)

print('== c78 ==')
v=78
e=117
f=41
calc_p_h(v, e, f)
p=12
h=29
check(v, e, f, p, h, verbose=True)

print('== c75 ==')
v=75
e=50+65
f=2+e-v
calc_p_h(v, e, f)
37 changes: 37 additions & 0 deletions bins/public_bin/bucky_ball.txt
@@ -0,0 +1,37 @@
50 white sticks
12*5+1=61 red sticks
12*6+2=74 connectors

+1 connector
+4 red sticks

==============
connectors: 75
white sticks: 50
red sticks: 65

all sticks: 50+65 = 115

===============
== c60 ==
60 90 32
v=60, e=90, f=32, p=12, h=20
True True True True
v=60, e=90, f=32, p=12, h=20
True True True True
== c70 ==
70 105 37
v=70, e=105, f=37, p=12, h=25
True True True True
v=70, e=105, f=37, p=12, h=25
True True True True
== c78 ==
78 117 41
v=78, e=117, f=41, p=12, h=29
True True True True
v=78, e=117, f=41, p=12, h=29
True True True True
== c75 ==
75 115 42
v=75, e=115, f=42, p=22, h=20
True True True True
16 changes: 16 additions & 0 deletions bins/public_bin/forkbomb-mod.sh
@@ -0,0 +1,16 @@
#!/bin/bash
myfunc()
{
N=$(cat /dev/stdin)
if [ $N -gt 0 ]
then
echo "$N"
myfunc $(expr $N - 1) #| xargs myfunc
fi
}

echo 10 | myfunc
# myfunc -10
# myfunc 0
# echo < /dev/stdin
# myfunc $(cat /dev/stdin)
135 changes: 76 additions & 59 deletions bins/public_bin/git-config-submitter.py
@@ -1,72 +1,89 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# TODO: global config? But then I wouldn't need this script. ;)
# TODO: GUI for name selection? list of previously used name+mail pairs?
# <pep8-80 compliant>

# .. todo:: global config? But then I wouldn't need this script. ;)
# .. todo:: GUI for name selection? list of previously used name+mail pairs?

import re
import sys
import argparse
import textwrap
import subprocess


def main():

# argparse
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent('''\
Configure name+mail in git more easily.
Example 1: Select a name+mail pair from one of the previous commits:
git-config-submitter.py
Example 2: Pass a name+mail pair using the format used in git log output, i.e. "name <mail>":
git-config-submitter.py "first last <user@host>"
'''))

parser.add_argument('submitter', nargs='?')
args = parser.parse_args()

# default name+mail values
an = None
ae = None

if args.submitter: # if submitter specified, parse it
s = sys.argv[1]
p = re.compile('(.*) <(.*)>')
m = p.match(s)
if m:
an, ae = m.groups()
print(an)
print(ae)

# argparse

description_string = '''
Configure name+mail in git more easily.
Example 1:
Select a name+mail pair from one of the previous commits:
git-config-submitter.py
Example 2:
Pass a name+mail pair using the format used in git log output,
i.e. "name <mail>":
git-config-submitter.py "first last <user@host>"
'''

parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent(description_string))

parser.add_argument('submitter', nargs='?')
args = parser.parse_args()

# default name+mail values
an = None
ae = None

if args.submitter: # if submitter specified, parse it
s = sys.argv[1]
p = re.compile('(.*) <(.*)>')
m = p.match(s)
if m:
an, ae = m.groups()
print(an)
print(ae)
else:
raise Exception(textwrap.dedent('''
Invalid name/mail string.
It should be of the form: "name <mail>"'''))
else: # if no submitter specified, get it from log
author_name_list = subprocess.check_output(
['git', 'log', '--pretty=format:%an'], universal_newlines=True)
author_name_list = author_name_list.split('\n')
author_mail_list = subprocess.check_output(
['git', 'log', '--pretty=format:%ae'], universal_newlines=True)
author_mail_list = author_mail_list.split('\n')
print(author_name_list[0:3])
print(author_mail_list[0:3])

for an_tmp, ae_tmp in zip(author_name_list, author_mail_list):
ans = input('Use {} <{}>? (y/n): '.format(an_tmp, ae_tmp))
if ans == 'y':
an = an_tmp
ae = ae_tmp
break

# apply name+mail
if an is not None and ae is not None:
print('Setting default commiter to:\n {} <{}>'.format(an, ae))
cmd = ['git', 'config', 'user.name', '{}'.format(an)]
subprocess.check_call(cmd)
cmd = ['git', 'config', 'user.email', '{}'.format(ae)]
subprocess.check_call(cmd)

print('You may fix the identity used for the last commit with:')
print(' git commit --amend --reset-author')
else:
raise Exception('Invalid name/mail string. It should be of the form: "name <mail>"')
else: # if no submitter specified, get it from log
author_name_list = subprocess.check_output(['git', 'log', '--pretty=format:%an'], universal_newlines=True).split('\n')
author_mail_list = subprocess.check_output(['git', 'log', '--pretty=format:%ae'], universal_newlines=True).split('\n')
print(author_name_list)
print(author_mail_list)

for an_tmp, ae_tmp in zip(author_name_list, author_mail_list):
ans = input('Use {} <{}>? (y/n): '.format(an_tmp, ae_tmp))
if ans == 'y':
an = an_tmp
ae = ae_tmp
break

# apply name+mail
if an is not None and ae is not None:
print('Setting default commiter to:\n {} <{}>'.format(an, ae))
cmd = ['git', 'config', 'user.name', '{}'.format(an)]
subprocess.check_call(cmd)
cmd = ['git', 'config', 'user.email', '{}'.format(ae)]
subprocess.check_call(cmd)

print('You may fix the identity used for the last commit with:')
print(' git commit --amend --reset-author')
else:
print('Nothing changed.')

return
print('Nothing changed.')

return

if __name__ == '__main__':
main()
main()
9 changes: 8 additions & 1 deletion bins/public_bin/link_tool.py
Expand Up @@ -9,9 +9,10 @@
TODO: Make converting symlinks to hard links easier.
CRITICAL BUG: If the link is a cross-device link, it will be removed, but fail to create a new hard link afterwards!
CRITICAL BUG: If the link is to a directory, it will be removed, but fail to create a new hard link afterwards!
example:
OSError: [Errno 18] Invalid cross-device link: '/usr/share/doc/texlive-doc/latex/tools/longtable.pdf' -> 'longtable.pdf'
TODO: check for cross-device links before any replacments.
TODO: check for cross-device links before any replacments. -> Or simply rename to tempfile, use try statement and rename back in case of failure.
'''

import argparse
Expand Down Expand Up @@ -131,6 +132,12 @@ def retargetLinks(arguments):
print('old_target = ' + old_target)
print('new_target = ' + new_target)
if os.path.exists(new_target):

# skip if target is a directory and not using symlinks
if os.path.isdir(new_target) and not arguments.symbolic:
print(new_target + ' is a directory. Hard linking not supported. Skipping ' + link_name, file=sys.stderr)
continue

if arguments.not_interactive:
ans = 'y'
else:
Expand Down
2 changes: 1 addition & 1 deletion bins/public_bin/magicOrganizer.py
Expand Up @@ -46,7 +46,7 @@
import tempfile
import shutil

from PyQt4 import QtGui
from PyQt5 import QtGui
import argparseui

def fromdos(filename):
Expand Down
37 changes: 0 additions & 37 deletions bins/public_bin/misc/colors.sh

This file was deleted.

24 changes: 24 additions & 0 deletions bins/public_bin/mr_robot.py
@@ -0,0 +1,24 @@
#!/usr/bin/env python3
# A very basic Mr.Robot-like terminal with a prompt before every line. :)
# (This is still one of my biggest disappointments from this otherwise very good series. :/ )
# TODO: Could possibly be improved with readline for history handling.

import subprocess

def main():
PS1 = 'root@elliot$ '
while(True):
cmd = input(PS1)
if cmd:
cmd_list = cmd.split()
try:
out = subprocess.check_output(cmd_list, universal_newlines=True, stderr=subprocess.STDOUT)
for i in out.split('\n'):
print(PS1 + i)
except subprocess.CalledProcessError as err:
print(PS1 + err.output)
except:
print('{}: command not found'.format(cmd_list[0]))

if __name__ == "__main__":
main()

0 comments on commit b025b63

Please sign in to comment.