Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/KIAaze/bin_and_dotfiles_p…
- Loading branch information
Showing
22 changed files
with
1,341 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
Oops, something went wrong.