From 011a1df4ac702c646822e0dc1fbd5f7c68e73d55 Mon Sep 17 00:00:00 2001 From: kjg Date: Sat, 16 May 2020 00:15:39 +0900 Subject: [PATCH 1/8] kjg upload --- kjg/cdist.org | 91 +++++++++++++++ kjg/dot-cdist/manifest/firewall | 10 ++ kjg/dot-cdist/manifest/init | 13 ++- kjg/dot-cdist/type/__all_in_one/manifest | 38 +++++++ .../type/__all_in_one/parameter/boolean | 1 + .../__all_in_one/parameter/optional_multiple | 1 + kjg/dot-cdist/type/__all_in_one/singleton | 0 kjg/dot-cdist/type/__colourful_file/manifest | 11 ++ .../parameter/optional_multiple | 1 + .../type/__my_dotfiles/files/.bashrc | 14 +++ kjg/dot-cdist/type/__my_dotfiles/files/.emacs | 106 ++++++++++++++++++ kjg/dot-cdist/type/__my_dotfiles/manifest | 8 ++ kjg/dot-cdist/type/__my_dotfiles/singleton | 0 .../type/__my_firewall/explorer/exists | 3 + .../type/__my_firewall/explorer/nfrule | 3 + kjg/dot-cdist/type/__my_firewall/files/basic | 1 + .../type/__my_firewall/gencode-remote | 5 + kjg/dot-cdist/type/__my_firewall/manifest | 24 ++++ kjg/dot-cdist/type/__my_firewall/singleton | 0 kjg/dot-cdist/type/__my_nginx/manifest | 3 + kjg/dot-cdist/type/__my_nginx/singleton | 0 .../type/__my_nginx_site/gencode-remote | 20 ++++ kjg/dot-cdist/type/__my_nginx_site/manifest | 41 +++++++ 23 files changed, 393 insertions(+), 1 deletion(-) create mode 100644 kjg/dot-cdist/manifest/firewall create mode 100644 kjg/dot-cdist/type/__all_in_one/manifest create mode 100644 kjg/dot-cdist/type/__all_in_one/parameter/boolean create mode 100644 kjg/dot-cdist/type/__all_in_one/parameter/optional_multiple create mode 100644 kjg/dot-cdist/type/__all_in_one/singleton create mode 100644 kjg/dot-cdist/type/__colourful_file/manifest create mode 100644 kjg/dot-cdist/type/__colourful_file/parameter/optional_multiple create mode 100644 kjg/dot-cdist/type/__my_dotfiles/files/.bashrc create mode 100644 kjg/dot-cdist/type/__my_dotfiles/files/.emacs create mode 100644 kjg/dot-cdist/type/__my_dotfiles/manifest create mode 100644 kjg/dot-cdist/type/__my_dotfiles/singleton create mode 100644 kjg/dot-cdist/type/__my_firewall/explorer/exists create mode 100644 kjg/dot-cdist/type/__my_firewall/explorer/nfrule create mode 100644 kjg/dot-cdist/type/__my_firewall/files/basic create mode 100644 kjg/dot-cdist/type/__my_firewall/gencode-remote create mode 100644 kjg/dot-cdist/type/__my_firewall/manifest create mode 100644 kjg/dot-cdist/type/__my_firewall/singleton create mode 100644 kjg/dot-cdist/type/__my_nginx/manifest create mode 100644 kjg/dot-cdist/type/__my_nginx/singleton create mode 100644 kjg/dot-cdist/type/__my_nginx_site/gencode-remote create mode 100644 kjg/dot-cdist/type/__my_nginx_site/manifest diff --git a/kjg/cdist.org b/kjg/cdist.org index ccc3085..ab709af 100644 --- a/kjg/cdist.org +++ b/kjg/cdist.org @@ -1001,3 +1001,94 @@ DEBUG: localhost: cache subpath: 421aa90e079fa326b6494f812ad13e79 TRACE: localhost: Saving cache: /tmp/tmp4n4p2hbt/421aa90e079fa326b6494f812ad13e79/data to /root/.cdist/cache/421aa90e079fa326b6494f812ad13e79 INFO: localhost: Finished successful run in 2.17 seconds VERBOSE: config: Total processing time for 1 host(s): 2.1842637062072754 + + +* cdist3 + + +* cdist4 +** Create a new type *__my_nginx* +On the target host find out which directory nginx includes --> /etc/nginx/sites-enabled +*** log +VERBOSE: cdist: version 6.5.5-3-g6f4649ef +INFO: localhost: Starting configuration run +VERBOSE: localhost: Running global explorers +VERBOSE: localhost: Running initial manifest /tmp/tmpchto21_m/421aa90e079fa326b6494f812ad13e79/data/conf/manifest/init +VERBOSE: localhost: Preparing object __my_nginx/ +VERBOSE: localhost: Running manifest and explorers for __my_nginx/ +VERBOSE: localhost: Running type explorers for +VERBOSE: localhost: Running type manifest /tmp/tmpchto21_m/421aa90e079fa326b6494f812ad13e79/data/conf/type/__my_nginx/manifest for object __my_nginx/ +VERBOSE: localhost: Preparing object __package/nginx +VERBOSE: localhost: Running manifest and explorers for __package/nginx +VERBOSE: localhost: Running type explorers for +VERBOSE: localhost: Running type manifest /tmp/tmpchto21_m/421aa90e079fa326b6494f812ad13e79/data/conf/type/__package/manifest for object __package/nginx +VERBOSE: localhost: Preparing object __package_apt/nginx +VERBOSE: localhost: Running manifest and explorers for __package_apt/nginx +VERBOSE: localhost: Running type explorers for +VERBOSE: localhost: Running object __package_apt/nginx +VERBOSE: localhost: Running object __package/nginx +VERBOSE: localhost: Running object __my_nginx/ +INFO: localhost: Finished successful run in 0.87 seconds +VERBOSE: config: Total processing time for 1 host(s): 0.8785049915313721 +** Create a new tyep *__my_nginx_site* +root@mynginx2:~#ls -al /etc/nginx/sites-enabled/ +total 16 +drwxr-xr-x 2 root root 4096 May 11 23:29 . +drwxr-xr-x 8 root root 4096 May 11 21:40 .. +lrwxrwxrwx 1 root root 34 May 11 21:40 default -> /etc/nginx/sites-available/default +-rw-r--r-- 1 root root 243 May 11 23:29 mynginx2.test.conf +-rw-r--r-- 1 root root 243 May 11 23:27 mynginx.test.conf +root@mynginx2:~# + +*** remove nginx and __my_nginx log +VERBOSE: cdist: version 6.5.5-3-g6f4649ef +INFO: mynginx2.test: Starting configuration run +VERBOSE: mynginx2.test: Running global explorers +VERBOSE: mynginx2.test: Running initial manifest /tmp/tmptq3y42m2/5e977ddad9a0047b183b6d2702795df4/data/conf/manifest/init +VERBOSE: mynginx2.test: Preparing object __my_nginx_site/mynginx2.test +VERBOSE: mynginx2.test: Running manifest and explorers for __my_nginx_site/mynginx2.test +VERBOSE: mynginx2.test: Running type explorers for +VERBOSE: mynginx2.test: Running type manifest /tmp/tmptq3y42m2/5e977ddad9a0047b183b6d2702795df4/data/conf/type/__my_nginx_site/manifest for object __my_nginx_site/mynginx2.test +ERROR: mynginx2.test: The requirements of the following objects could not be resolved: +__file/etc/nginx/sites-enabled/mynginx2.test.conf requires: + __package/nginx +__file/etc/nginx/sites-enabled/mynginx2.test.conf autorequires: + +__my_nginx_site/mynginx2.test requires: + +__my_nginx_site/mynginx2.test autorequires: + __file/etc/nginx/sites-enabled/mynginx2.test.conf +VERBOSE: config: Total processing time for 1 host(s): 0.6650142669677734 +ERROR: cdist: Failed to configure the following hosts: mynginx2.tes + +--> nginx is removed and "require" check nginx(__package/nginx) + + +* cdist5 +** What is the difference between gencode-remote and the remote code? + +remote code is running on cdist command(cdist config --remote-copy REMOTE_COPY) +gencode-remote is running on cdist type + +remote_copy - use for remote copy with cdist command +remote_exec - use for remote execution with cdist command + +** What is the difference between gencode-local and gencode-remote? +gencode-local is executed locall, otherwise gencode-remote is executed on the targethost + +** Locate a type that comes with upstream cdist that uses gencode-local - which one is it? Why does it need gencode-local? +__ungleich_dhparam + +For running a specific local package +ex) openssl dhparam -outform PEM -out ${destination}/${domain}_dhparam.pem $keysize + + + + + + + +* cdist6 +** __all_in_one +i used singleton, because it does not need specific host. +** __firewall diff --git a/kjg/dot-cdist/manifest/firewall b/kjg/dot-cdist/manifest/firewall new file mode 100644 index 0000000..da93aa2 --- /dev/null +++ b/kjg/dot-cdist/manifest/firewall @@ -0,0 +1,10 @@ +case "$__target_host" in + # Everybody has this + localhost) + __package nftables + require="__package/nftables" __my_firewall --file basic + ;; + *) + __my_nginx + __my_nginx_site $__target_host #test +esac \ No newline at end of file diff --git a/kjg/dot-cdist/manifest/init b/kjg/dot-cdist/manifest/init index 3f3a6db..6fd3e2c 100644 --- a/kjg/dot-cdist/manifest/init +++ b/kjg/dot-cdist/manifest/init @@ -1,6 +1,17 @@ +#!/bin/sh + +sh -e "$__manifest/firewall" + case "$__target_host" in # Everybody has this localhost) - __my_computer + #__my_computer + #__colourful_file test --colour test1 --colour test2 + #__my_dotfiles + __all_in_one --with-x --extra-packages git ;; + *) + __my_nginx + __my_nginx_site $__target_host #test esac + diff --git a/kjg/dot-cdist/type/__all_in_one/manifest b/kjg/dot-cdist/type/__all_in_one/manifest new file mode 100644 index 0000000..87057e4 --- /dev/null +++ b/kjg/dot-cdist/type/__all_in_one/manifest @@ -0,0 +1,38 @@ +#!/bin/sh + +os=$(cat "$__global/explorer/os") + +case "$os" in + alpine) + os_pkgs="netcat-openbsd and tshark" + ;; + debian|devuan) + os_pkgs="netcat tshark" + ;; + fedora) + os_pkgs="nmap-ncat wireshark-cli" + ;; + *) + echo "OS $os currently not supported" >&2 + exit 1 + ;; +esac + +base_pkgs="socat sipcalc sudo" + + +if [! -f ${__object}/parameter/with-x ]; then + for bpkg in ${base_pkgs}; do + __package ${bpkg} --state present + done + + for opkg in ${os_pkgs}; do + __package ${opkg} --state present + done +fi + +if [ -f "$__object/parameter/extra-packages" ]; then + for epkg in $(cat $__object/parameter/extra-packages); do + __package $epkg --state present + done +fi diff --git a/kjg/dot-cdist/type/__all_in_one/parameter/boolean b/kjg/dot-cdist/type/__all_in_one/parameter/boolean new file mode 100644 index 0000000..b333e3c --- /dev/null +++ b/kjg/dot-cdist/type/__all_in_one/parameter/boolean @@ -0,0 +1 @@ +with-x \ No newline at end of file diff --git a/kjg/dot-cdist/type/__all_in_one/parameter/optional_multiple b/kjg/dot-cdist/type/__all_in_one/parameter/optional_multiple new file mode 100644 index 0000000..2cfc07b --- /dev/null +++ b/kjg/dot-cdist/type/__all_in_one/parameter/optional_multiple @@ -0,0 +1 @@ +extra-packages diff --git a/kjg/dot-cdist/type/__all_in_one/singleton b/kjg/dot-cdist/type/__all_in_one/singleton new file mode 100644 index 0000000..e69de29 diff --git a/kjg/dot-cdist/type/__colourful_file/manifest b/kjg/dot-cdist/type/__colourful_file/manifest new file mode 100644 index 0000000..e7470fd --- /dev/null +++ b/kjg/dot-cdist/type/__colourful_file/manifest @@ -0,0 +1,11 @@ +#!/bin/sh + +DOMAIN_NAME="$__object_id" + +COLOUR=$(cat "$__object/parameter/colour") + +if [ -f "$__object/parameter/colour" ]; then + for col in $(cat $__object/parameter/colour); do + echo "colour="$col >> ~/colourful + done +fi diff --git a/kjg/dot-cdist/type/__colourful_file/parameter/optional_multiple b/kjg/dot-cdist/type/__colourful_file/parameter/optional_multiple new file mode 100644 index 0000000..a9c4dd8 --- /dev/null +++ b/kjg/dot-cdist/type/__colourful_file/parameter/optional_multiple @@ -0,0 +1 @@ +colour \ No newline at end of file diff --git a/kjg/dot-cdist/type/__my_dotfiles/files/.bashrc b/kjg/dot-cdist/type/__my_dotfiles/files/.bashrc new file mode 100644 index 0000000..9169adb --- /dev/null +++ b/kjg/dot-cdist/type/__my_dotfiles/files/.bashrc @@ -0,0 +1,14 @@ +# .bashrc + +# User specific aliases and functions + +alias rm='rm -i' +alias cp='cp -i' +alias mv='mv -i' + +# Source global definitions +if [ -f /etc/bashrc ]; then + . /etc/bashrc +fi + +export PATH=$HOME/cdist/bin:$PATH diff --git a/kjg/dot-cdist/type/__my_dotfiles/files/.emacs b/kjg/dot-cdist/type/__my_dotfiles/files/.emacs new file mode 100644 index 0000000..5c997f2 --- /dev/null +++ b/kjg/dot-cdist/type/__my_dotfiles/files/.emacs @@ -0,0 +1,106 @@ +;; Added by Package.el. This must come before configurations of +;; installed packages. Don't delete this line. If you don't want it, +;; just comment it out by adding a semicolon to the start of the line. +;; You may delete these explanatory comments. +(require 'package) +(add-to-list 'package-archives + '("melpa" . "http://melpa.org/packages/") t) +(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t) +(package-initialize) + + + +(global-set-key (kbd "") (lambda () (interactive) (find-file (concat "~/ungleich-learning-circle/kjg/learning-"(system-name)"-"(format-time-string "%Y")".org")))) +(global-set-key (kbd "C-x g") 'magit-status) +(global-set-key (kbd "C-c a") 'org-agenda) +(global-set-key (kbd "") 'org-todo-list) + +(custom-set-variables + ;; custom-set-variables was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + '(epg-gpg-program "/usr/local/bin/gpg") + '(org-agenda-files + (quote + ("~/ungleich-learning-circle/kjg/todo.org" "~/learning.org"))) + ;;'(org-directory (expand-file-name "~/ungleich-learning-circle/kjg/")) + '(package-selected-packages (quote (org org-gnome org-dp ## which-key magit))) + '(send-mail-function (quote sendmail-send-it))) +(custom-set-faces + ;; custom-set-faces was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + ) + +(require 'epa-file) + +(epa-file-enable) + +(setq mu4e-mu-binary "/usr/local/bin/mu") + +(add-to-list 'load-path "/usr/local/share/emacs/site-lisp/mu/mu4e") +(require 'mu4e) + +(setq + mue4e-headers-skip-duplicates t + mu4e-view-show-images t + mu4e-view-show-addresses t + mu4e-compose-format-flowed nil + mu4e-date-format "%y/%m/%d" + mu4e-headers-date-format "%Y/%m/%d" + mu4e-change-filenames-when-moving t + mu4e-attachments-dir "~/Downloads" + + mu4e-maildir "~/Maildir/ungleich" ;; top-level Maildir + ;; note that these folders below must start with / + ;; the paths are relative to maildir root + mu4e-refile-folder "/Archive" + mu4e-sent-folder "/Sent" + mu4e-drafts-folder "/Drafts" + mu4e-trash-folder "/Trash" + mu4e-reply-to-address "jinguk.kwon@ungleich.ch" + user-mail-address "jinguk.kwon@ungleich.ch" + user-full-name "kjg") + +;; this setting allows to re-sync and re-index mail +;; by pressing U +(setq mu4e-get-mail-command "mbsync -a") + +(setq mail-host-address "mail.ungleich.ch") + + +(setq send-mail-function 'smtpmail-send-it + message-send-mail-function 'smtpmail-send-it + user-mail-address "jinguk.kwon@ungleich.ch" + smtpmail-starttls-credentials '(("smtp.ungleich.ch" 587 nil nil)) + smtpmail-auth-credentials "~/.authinfo.gpg" + smtpmail-default-smtp-server "smtp.ungleich.ch" + smtpmail-smtp-server "smtp.ungleich.ch" + smtpmail-smtp-service 587 + smtpmail-smtp-user "jinguk.kwon@ungleich.ch" + smtpmail-debug-info t + smtpmail-debug-verb t) + ;;starttls-extra-arguments nil + ;;starttls-gnutls-program (executable-find "gnutls-cli") + ;;smtpmail-warn-about-unknown-extensions t + ;;starttls-use-gnutls t) + +(require 'smtpmail) + +;;store org-mode links to messages +(require 'org-mu4e) + +(define-key mu4e-headers-mode-map (kbd "C-c c") 'mu4e-org-store-and-capture) +(define-key mu4e-view-mode-map (kbd "C-c c") 'mu4e-org-store-and-capture) + +(setq org-directory (expand-file-name "~/ungleich-learning-circle/kjg/")) +;;store link to message if in header view, not to header query +(setq org-mu4e-link-query-in-headers-mode nil) + +(setq org-capture-templates + '(("t" "todo" entry (file+headline (lambda() (concat "~/ungleich-learning-circle/kjg/todo-"(system-name)"-"(format-time-string "%Y")".org")) "Tasks") + "* TODO [#A] %?\nSCHEDULED: %(org-insert-time-stamp (org-read-date nil t \"+0d\"))\n%a\n"))) + +(setq org-log-done 'time) diff --git a/kjg/dot-cdist/type/__my_dotfiles/manifest b/kjg/dot-cdist/type/__my_dotfiles/manifest new file mode 100644 index 0000000..f322198 --- /dev/null +++ b/kjg/dot-cdist/type/__my_dotfiles/manifest @@ -0,0 +1,8 @@ +#!/bin/sh + +cd "$__type/files/" +dotfiles=$(ls -a .[A-z]*) +for df in $dotfiles; do + __file ~/$df \ + --mode 0644 --source "$__type/files/$df" +done \ No newline at end of file diff --git a/kjg/dot-cdist/type/__my_dotfiles/singleton b/kjg/dot-cdist/type/__my_dotfiles/singleton new file mode 100644 index 0000000..e69de29 diff --git a/kjg/dot-cdist/type/__my_firewall/explorer/exists b/kjg/dot-cdist/type/__my_firewall/explorer/exists new file mode 100644 index 0000000..1839cf9 --- /dev/null +++ b/kjg/dot-cdist/type/__my_firewall/explorer/exists @@ -0,0 +1,3 @@ +#!/bin/sh + +nft -V | grpe v* || true diff --git a/kjg/dot-cdist/type/__my_firewall/explorer/nfrule b/kjg/dot-cdist/type/__my_firewall/explorer/nfrule new file mode 100644 index 0000000..ffaadf5 --- /dev/null +++ b/kjg/dot-cdist/type/__my_firewall/explorer/nfrule @@ -0,0 +1,3 @@ + + +nft list ruleset diff --git a/kjg/dot-cdist/type/__my_firewall/files/basic b/kjg/dot-cdist/type/__my_firewall/files/basic new file mode 100644 index 0000000..30d74d2 --- /dev/null +++ b/kjg/dot-cdist/type/__my_firewall/files/basic @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/kjg/dot-cdist/type/__my_firewall/gencode-remote b/kjg/dot-cdist/type/__my_firewall/gencode-remote new file mode 100644 index 0000000..28c684f --- /dev/null +++ b/kjg/dot-cdist/type/__my_firewall/gencode-remote @@ -0,0 +1,5 @@ +#!/bin/sh -e + +if [! -f echo "diff /etc/my-nftables /etc/readrule"]; then + echo "nft -f /etc/my-nftables" +fi diff --git a/kjg/dot-cdist/type/__my_firewall/manifest b/kjg/dot-cdist/type/__my_firewall/manifest new file mode 100644 index 0000000..154d40b --- /dev/null +++ b/kjg/dot-cdist/type/__my_firewall/manifest @@ -0,0 +1,24 @@ +#!/bin/sh + +os=$(cat "$__global/explorer/os") + +nft_path="/etc/my-nftables" + +if [ ! -f "$__global/explorer/exists" ];then + echo "crrently no nft" >&2 + exit 1 +fi + +if ["-" -eq "$__object/parameter/file" ]; then + filename="$__object/stdin" + +else + filename=($__object/parameter/file) +fi + +__file ${nft_path} --mode 644 --source "$__type/files/${filename}" + + +if [ -f "$__global/explorer/nfrule" ]; then + echo "$__global/explorer//nfrule" > /etc/readrule +fi diff --git a/kjg/dot-cdist/type/__my_firewall/singleton b/kjg/dot-cdist/type/__my_firewall/singleton new file mode 100644 index 0000000..e69de29 diff --git a/kjg/dot-cdist/type/__my_nginx/manifest b/kjg/dot-cdist/type/__my_nginx/manifest new file mode 100644 index 0000000..c231a90 --- /dev/null +++ b/kjg/dot-cdist/type/__my_nginx/manifest @@ -0,0 +1,3 @@ +#!/bin/sh + +__package nginx diff --git a/kjg/dot-cdist/type/__my_nginx/singleton b/kjg/dot-cdist/type/__my_nginx/singleton new file mode 100644 index 0000000..e69de29 diff --git a/kjg/dot-cdist/type/__my_nginx_site/gencode-remote b/kjg/dot-cdist/type/__my_nginx_site/gencode-remote new file mode 100644 index 0000000..e18e240 --- /dev/null +++ b/kjg/dot-cdist/type/__my_nginx_site/gencode-remote @@ -0,0 +1,20 @@ +os=$(cat "$__global/explorer/os") + +case "$os" in + devuan) + CONF_DIR=/etc/nginx/sites-enabled + ;; + alpine) + CONF_DIR=/etc/nginx/conf.d + ;; + *) + echo "OS $os currently not supported" >&2 + exit 1 + ;; +esac + +DOMAIN_NAME="$__object_id" + +if grep -q "^__file${CONF_DIR}/${DOMAIN_NAME}" "$__messages_in"; then + echo 'service nginx reload' +fi diff --git a/kjg/dot-cdist/type/__my_nginx_site/manifest b/kjg/dot-cdist/type/__my_nginx_site/manifest new file mode 100644 index 0000000..3362f90 --- /dev/null +++ b/kjg/dot-cdist/type/__my_nginx_site/manifest @@ -0,0 +1,41 @@ +#!/bin/sh + +os=$(cat "$__global/explorer/os") + +case "$os" in + devuan) + CONF_DIR=/etc/nginx/sites-enabled + ;; + alpine) + CONF_DIR=/etc/nginx/conf.d + ;; + *) + echo "OS $os currently not supported" >&2 + exit 1 + ;; +esac + +DOMAIN_NAME="$__object_id" +WEB_ROOT=/var/www/html/${DOMAIN_NAME} + +__directory $WEB_ROOT --parents --mode 0644 + +require="__package/nginx" __file "${CONF_DIR}/${DOMAIN_NAME}.conf" \ + --mode 0644 --source - << EOF +server { + listen *:80; + listen [::]:80; + + server_name $DOMAIN_NAME; + root $WEB_ROOT; + + location /.well-known/acme-challenge/ { + root $WEB_ROOT; + } + + # Everything else -> ssl + location / { + return 301 https://\$host\$request_uri; + } +} +EOF From 79a3c80eed04b0325272909c3d5ff4bbd07986b9 Mon Sep 17 00:00:00 2001 From: kjg Date: Mon, 18 May 2020 22:41:27 +0900 Subject: [PATCH 2/8] [Python #1] create ex1 --- kjg/python-the-hard-way/e1.py | 7 +++++++ kjg/python.org | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 kjg/python-the-hard-way/e1.py create mode 100644 kjg/python.org diff --git a/kjg/python-the-hard-way/e1.py b/kjg/python-the-hard-way/e1.py new file mode 100644 index 0000000..6986148 --- /dev/null +++ b/kjg/python-the-hard-way/e1.py @@ -0,0 +1,7 @@ +print("Hello World!") +print("Hello Again") +print("I like typing this.") +print("This is fun.") +print('Yay! Printing.') +print("I'd much rather you 'not'.") +print('I "said" do not touch this.') diff --git a/kjg/python.org b/kjg/python.org new file mode 100644 index 0000000..13d37bc --- /dev/null +++ b/kjg/python.org @@ -0,0 +1,19 @@ +*python + +*** Python #1: +**** ex0 +**** ex1 +>>> print("Hello World!") +... print("Hello Again") +... print("I like typing this.") +... print("This is fun.") +... print('Yay! Printing.') +... print("I'd much rather you 'not'.") +... print('I "said" do not touch this.') +Hello World! +Hello Again +I like typing this. +This is fun. +Yay! Printing. +I'd much rather you 'not'. +I "said" do not touch this. From 2505a9e78c2c156ced5396e2334ed8994af20af6 Mon Sep 17 00:00:00 2001 From: kjg Date: Mon, 18 May 2020 22:46:09 +0900 Subject: [PATCH 3/8] [Python #1] create ex2 --- kjg/python-the-hard-way/e2.py | 9 +++++++++ kjg/python.org | 3 +++ kjg/python.org~ | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 kjg/python-the-hard-way/e2.py create mode 100644 kjg/python.org~ diff --git a/kjg/python-the-hard-way/e2.py b/kjg/python-the-hard-way/e2.py new file mode 100644 index 0000000..6f3b06c --- /dev/null +++ b/kjg/python-the-hard-way/e2.py @@ -0,0 +1,9 @@ +# A comment, this is so you can read your program later. +# Anything after the # is ignored by python. + +print("I could have code like this.") # and the comment after is ignored + +# You can also use a comment to "disable" or comment out code: +# print("This won't run.") + +print("This will run.") diff --git a/kjg/python.org b/kjg/python.org index 13d37bc..0d17b72 100644 --- a/kjg/python.org +++ b/kjg/python.org @@ -17,3 +17,6 @@ This is fun. Yay! Printing. I'd much rather you 'not'. I "said" do not touch this. +**** ex2 +I could have code like this. +This will run. diff --git a/kjg/python.org~ b/kjg/python.org~ new file mode 100644 index 0000000..13d37bc --- /dev/null +++ b/kjg/python.org~ @@ -0,0 +1,19 @@ +*python + +*** Python #1: +**** ex0 +**** ex1 +>>> print("Hello World!") +... print("Hello Again") +... print("I like typing this.") +... print("This is fun.") +... print('Yay! Printing.') +... print("I'd much rather you 'not'.") +... print('I "said" do not touch this.') +Hello World! +Hello Again +I like typing this. +This is fun. +Yay! Printing. +I'd much rather you 'not'. +I "said" do not touch this. From dc9b72cffe419a1e0d73c77de363fff90665c0f8 Mon Sep 17 00:00:00 2001 From: kjg Date: Mon, 18 May 2020 22:55:52 +0900 Subject: [PATCH 4/8] [Python #1] create e3.py --- kjg/python-the-hard-way/e3.py | 23 +++++++++++++++++++++++ kjg/python.org | 16 ++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 kjg/python-the-hard-way/e3.py diff --git a/kjg/python-the-hard-way/e3.py b/kjg/python-the-hard-way/e3.py new file mode 100644 index 0000000..e7067be --- /dev/null +++ b/kjg/python-the-hard-way/e3.py @@ -0,0 +1,23 @@ +print(" I will now count my chickens : ") + +print("Hens", 25 + 30 / 6) +print("Roosters", 100 - 25 * 3 % 4 ) + +print("Now I will count the eggs : ") + +print(3 + 2 + 1 - 5 + 4 % 2 -1 / 4 + 6) + +print("Is it true that 3 + 2 < 5 - 7?") + +print(3 + 2 < 5 -7 ) + +print("What is 3 + 2?", 3 + 2) +print("What is 5 - 7?", 5 - 7) + +print("Oh, that;s why it's Fasle.") + +print("How about some more.") + +print("Is it greater?", 5 > -2) +print("Is it greater or equal?", 5 >= -2) +print("Is it less or equal?", 5 <= -2) diff --git a/kjg/python.org b/kjg/python.org index 0d17b72..4dea597 100644 --- a/kjg/python.org +++ b/kjg/python.org @@ -20,3 +20,19 @@ I "said" do not touch this. **** ex2 I could have code like this. This will run. + +**** ex3 +I will now count my chickens : +Hens 30.0 +Roosters 97 +Now I will count the eggs : +6.75 +Is it true that 3 + 2 < 5 - 7? +False +What is 3 + 2? 5 +What is 5 - 7? -2 +Oh, that;s why it's Fasle. +How about some more. +Is it greater? True +Is it greater or equal? True +Is it less or equal? False From 8127e6bc71d26c5ac8377be2b0863a417e36cebf Mon Sep 17 00:00:00 2001 From: kjg Date: Mon, 18 May 2020 23:01:21 +0900 Subject: [PATCH 5/8] [Python #1] create e4.py --- kjg/python-the-hard-way/e4.py | 17 +++++++++++++++++ kjg/python.org | 7 +++++++ 2 files changed, 24 insertions(+) create mode 100644 kjg/python-the-hard-way/e4.py diff --git a/kjg/python-the-hard-way/e4.py b/kjg/python-the-hard-way/e4.py new file mode 100644 index 0000000..edec0a3 --- /dev/null +++ b/kjg/python-the-hard-way/e4.py @@ -0,0 +1,17 @@ +cars = 100 +space_in_a_car = 4.0 +drivers = 30 +passengers = 90 +cars_not_driven = cars - drivers +cars_driven = drivers +carpool_capacity = cars_driven * space_in_a_car +average_passengers_per_car = passengers / cars_driven + + +print("There are", cars, "cars available.") +print("There are only", drivers, "drivers available.") +print("There will be", cars_not_driven, "empty cars today.") +print("We can transport", carpool_capacity, "people today.") +print("We have", passengers, "to carpool today.") +print("We need to put about", average_passengers_per_car, "in each car.") + diff --git a/kjg/python.org b/kjg/python.org index 4dea597..885fb90 100644 --- a/kjg/python.org +++ b/kjg/python.org @@ -36,3 +36,10 @@ How about some more. Is it greater? True Is it greater or equal? True Is it less or equal? False +**** ex4 +There are 100 cars available. +There are only 30 drivers available. +There will be 70 empty cars today. +We can transport 120.0 people today. +We have 90 to carpool today. +We need to put about 3.0 in each car. From 3607d22d2017831f604bef98a1d6febedff80fd9 Mon Sep 17 00:00:00 2001 From: kjg Date: Mon, 18 May 2020 23:17:12 +0900 Subject: [PATCH 6/8] [Python #1]create e5.py --- kjg/python-the-hard-way/e5.py | 18 ++++++++++++++++++ kjg/python.org | 9 +++++++++ 2 files changed, 27 insertions(+) create mode 100644 kjg/python-the-hard-way/e5.py diff --git a/kjg/python-the-hard-way/e5.py b/kjg/python-the-hard-way/e5.py new file mode 100644 index 0000000..a7e62bc --- /dev/null +++ b/kjg/python-the-hard-way/e5.py @@ -0,0 +1,18 @@ +my_name = 'Zed A. Shaw' +my_age=35 # notalie +my_height = 74 # inches +my_weight = 180 # lbs +my_eyes = 'Blue' +my_teeth = 'White' +my_hair = 'Brown' + +print(f"Let's talk about {my_name}.") +print(f"He's {my_height} inches tall.") +print(f"He's {my_weight} pounds heavy.") +print("Actually that's not too heavy.") +print(f"He's got {my_eyes} eyes and {my_hair} hair.") +print(f"His teeth are usually {my_teeth} depending on the coffee.") + +# this line is tricky, try to get it exactly right +total = my_age + my_height + my_weight +print(f"If I add {my_age}, {my_height}, and {my_weight} I get {total}.") diff --git a/kjg/python.org b/kjg/python.org index 885fb90..5c59d47 100644 --- a/kjg/python.org +++ b/kjg/python.org @@ -43,3 +43,12 @@ There will be 70 empty cars today. We can transport 120.0 people today. We have 90 to carpool today. We need to put about 3.0 in each car. + +**** ex5 +Let's talk about Zed A. Shaw. +He's 74 inches tall. +He's 180 pounds heavy. +Actually that's not too heavy. +He's got Blue eyes and Brown hair. +His teeth are usually White depending on the coffee. +If I add 35, 74, and 180 I get 289. From 63495c51de423e312c1a9ea43babf94860f8d50f Mon Sep 17 00:00:00 2001 From: kjg Date: Mon, 18 May 2020 23:25:54 +0900 Subject: [PATCH 7/8] [Python #1] create e6.py --- kjg/python-the-hard-way/e6.py | 22 ++++++++++++++++++++++ kjg/python.org | 7 +++++++ 2 files changed, 29 insertions(+) create mode 100644 kjg/python-the-hard-way/e6.py diff --git a/kjg/python-the-hard-way/e6.py b/kjg/python-the-hard-way/e6.py new file mode 100644 index 0000000..b850e43 --- /dev/null +++ b/kjg/python-the-hard-way/e6.py @@ -0,0 +1,22 @@ +types_of_people = 10 +x = f"There are {types_of_people} types of people." + +binary = "binary" +do_not = "don't" +y = f"Those who know {binary} and those who {do_not}." + +print(x) +print(y) + +print(f"I said: {x}") +print(f"I also said: '{y}'") + +hilarious = False +joke_evaluation = "Isn't that joke so funny?! {}" + +print(joke_evaluation.format(hilarious)) + +w = "This is the left side of..." +e = "a string with a right side." + +print(w + e) diff --git a/kjg/python.org b/kjg/python.org index 5c59d47..7e14ff7 100644 --- a/kjg/python.org +++ b/kjg/python.org @@ -52,3 +52,10 @@ Actually that's not too heavy. He's got Blue eyes and Brown hair. His teeth are usually White depending on the coffee. If I add 35, 74, and 180 I get 289. +**** ex6 +There are 10 types of people. +Those who know binary and those who don't. +I said: There are 10 types of people. +I also said: 'Those who know binary and those who don't.' +Isn't that joke so funny?! False +This is the left side of...a string with a right side. From 9c8e7d9045c9e2084afc8505c194a71e0b14f4cf Mon Sep 17 00:00:00 2001 From: kjg Date: Mon, 18 May 2020 23:35:46 +0900 Subject: [PATCH 8/8] [Python #1] create e7.py --- kjg/python-the-hard-way/e7.py | 21 +++++++++++++++++++++ kjg/python.org | 9 ++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 kjg/python-the-hard-way/e7.py diff --git a/kjg/python-the-hard-way/e7.py b/kjg/python-the-hard-way/e7.py new file mode 100644 index 0000000..b050d14 --- /dev/null +++ b/kjg/python-the-hard-way/e7.py @@ -0,0 +1,21 @@ +print("Mary had a little lamb.") +print("Its fleece was white as {}.".format('snow')) +print("And everywhere that Mary went.") +print("." * 10) # what'd that do? + +end1 = "C" +end2 = "h" +end3 = "e" +end4 = "e" +end5 = "s" +end6 = "e" +end7 = "B" +end8 = "u" +end9 = "r" +end10 = "g" +end11 = "e" +end12 = "r" + +# watch end = ' ' at the end. try removing it to see what happens +print(end1 + end2 + end3 + end4 + end5 + end6, end=' ') +print(end7 + end8 + end9 + end10 + end11 + end12) diff --git a/kjg/python.org b/kjg/python.org index 7e14ff7..9cada1d 100644 --- a/kjg/python.org +++ b/kjg/python.org @@ -1,4 +1,5 @@ -*python + +* learning python *** Python #1: **** ex0 @@ -59,3 +60,9 @@ I said: There are 10 types of people. I also said: 'Those who know binary and those who don't.' Isn't that joke so funny?! False This is the left side of...a string with a right side. +**** ex7 +Mary had a little lamb. +Its fleece was white as snow. +And everywhere that Mary went. +.......... +Cheese Burger