summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgarhve <git@garhve.com>2023-01-03 19:05:48 +0800
committergarhve <git@garhve.com>2023-01-03 19:05:48 +0800
commitfaa108dc5c84f5c4aecee35a2f490eeedc85cb0d (patch)
tree30193abd2dceb21aab9a536f786f959dedd018f1
parent0e89468188b9d347495dad5b98af137e5f477432 (diff)
add files
-rw-r--r--.gitmodules6
-rwxr-xr-xbash/blog-zola.sh108
-rw-r--r--c/tree/basic.c27
-rw-r--r--c/tree/main.c2
m---------codecrafters/codecrafters-docker-c0
m---------codecrafters/codecrafters-grep-rust0
-rw-r--r--lua/6.lua61
-rw-r--r--rust/theBook/chapter-10-generic-types-traits-lifetimes/generic-type/Cargo.toml8
-rw-r--r--rust/theBook/chapter-10-generic-types-traits-lifetimes/generic-type/src/main.rs45
-rw-r--r--rust/theBook/chapter-10-generic-types-traits-lifetimes/non-generic-largest.rs34
-rw-r--r--rust/theBook/chapter-10-generic-types-traits-lifetimes/traits/Cargo.toml8
-rw-r--r--rust/theBook/chapter-10-generic-types-traits-lifetimes/traits/src/lib.rs29
-rw-r--r--rust/theBook/chapter-10-generic-types-traits-lifetimes/traits/src/main.rs23
13 files changed, 340 insertions, 11 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..e1386b3
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,6 @@
+[submodule "codecrafters/codecrafters-docker-c"]
+ path = codecrafters/codecrafters-docker-c
+ url = https://git.codecrafters.io/268947ed1a50ba48
+[submodule "codecrafters/codecrafters-grep-rust"]
+ path = codecrafters/codecrafters-grep-rust
+ url = https://git.codecrafters.io/cdd73d1d6425eaef
diff --git a/bash/blog-zola.sh b/bash/blog-zola.sh
new file mode 100755
index 0000000..90f3050
--- /dev/null
+++ b/bash/blog-zola.sh
@@ -0,0 +1,108 @@
+#!/usr/bin/env sh
+
+######################################################################
+# @author : garhve (dev@garhve.com)
+# @file : blog
+# @created : Friday Dec 09, 2022 16:09:42 CST
+#
+# @description : simplify blog publishing, it only can use in blog dir
+######################################################################
+
+# usage: prog funct
+
+push() {
+ read -r -p "Do you want to push?[y/n] " ans
+ if [ "$ans" == 'y' ]; then
+ zola build
+ git add .
+ if [ ! -z "$(git status | grep 'Changes to be committed')" ]; then
+ read -r -p "commit message: " msg
+ git commit -m "$msg"
+ git push origin main
+ fi
+ echo -e "push done"
+ fi
+}
+
+edit() {
+ path="content/post"
+
+ # --- get editing file
+ choice=1
+ declare -a arr
+ for file in $path/*; do
+ [[ "$file" == *"_index.md" ]] && continue
+ echo -ne "($choice)\x1b[0;32m${file##*/}\x1b[0m " # n get rid of trailing new line, e strip backslash
+ arr[$choice]="$file"
+ choice=$((choice+1))
+ done
+ echo ""
+ read -r -p "please choose file by number you want to edit from above: " num
+ [[ "$num" == "q" ]] && exit 0
+ vim "${arr[$num]}"
+ # --- end
+ echo -e "edit done\n"
+
+ push
+ echo -e "\nall done"
+}
+
+new() {
+ read -r -p "blog name: " name
+ path="content/post/$name"
+
+ if [ ! -f "$path".md ]; then
+
+ # get basic format
+ d="$(date +%F)"
+ read -r -p "category: " category
+ read -r -p "tag: " tags
+ read -r -p "math support [y/n]: " m
+ if [ "${m,,}" == 'y' ]; then
+ math_support="true"
+ else
+ math_support="false"
+ fi
+
+ cat << EOF > "$path".md
++++
+title = "$name"
+date = $d
+[taxonomies]
+categories = ["$category"]
+tags = ["$tags"]
+[extra]
+math = $math_support
++++
+EOF
+
+ vim "$path".md
+ [ "$?" -eq 0 ] && echo "creation done"
+ [ "$?" -ne 0 ] && echo "creation fail, please check error" && exit 1
+
+ else
+ echo "File exist"
+ fi
+
+ read -r -p "do you want to edit now?[y/n] " ans
+ [ "${ans,,}" == 'y' ] && vim "$path/$name.md" && echo "edit done"
+
+ push
+
+ echo -e "\nall done"
+}
+
+list() {
+ echo -e "\x1b[1;34mList content:\x1b[0m"
+ tree ./content/post
+}
+
+
+funct="new/edit/push/ls"
+
+[ $# -lt 1 ] && echo "usage: $(basename $0) $funct"
+
+[ $1 == "new" ] && new
+[ $1 == "edit" ] && edit
+[ $1 == "push" ] && push
+[ $1 == "ls" ] && list
diff --git a/c/tree/basic.c b/c/tree/basic.c
index aa95497..99bb23f 100644
--- a/c/tree/basic.c
+++ b/c/tree/basic.c
@@ -7,6 +7,7 @@
#include "tree.h"
+// error and init and empty function
void error(const char * str)
{
perror(str);
@@ -48,27 +49,34 @@ void allocText(char ** text, const char * str, size_t len)
*text = (char *) calloc (len, sizeof(char));
if (!*text)
error("newly allocation failed");
- memmove(*text,str,len+1);
+ memmove(*text,str,len);
}
}
-nodes * addnodes(const char * d_name, int level)
+size_t strsize(const char * str)
+{
+ size_t new = 0;
+ while ( *(str+new) != '\0')
+ new++;
+ return new;
+}
+
+nodes * addnodes(const char * d_name, size_t level)
{
nodes * new = (nodes *) calloc (1,sizeof(nodes));
if (!new)
error("allocation for new node failed");
- new->len = strlen(d_name);
+ new->len = strsize(d_name);
new->level = level;
new->fod = checkdir(d_name);
- allocText(&new->text, d_name, new->len);
- allocText(&new->text, '\0', 1);
+ allocText(&new->text, d_name, new->len+1);
return new;
}
-void addreg(regfile * head, const char * d_name, int level)
+void addreg(regfile * head, const char * d_name, size_t level)
{
regfile * new = head;
@@ -82,7 +90,7 @@ void addreg(regfile * head, const char * d_name, int level)
new->next->next = NULL;
}
-void extractContent(regfile * head, const char * parent, int level)
+void extractContent(regfile * head, const char * parent, size_t level)
{
DIR * d = opendir(parent);
struct dirent * dir;
@@ -93,14 +101,13 @@ void extractContent(regfile * head, const char * parent, int level)
while ((dir = readdir(d))) {
if (dir->d_name[1] == '.' || (dir->d_name[0] == '.' && dir->d_name[1] == '\0'))
continue;
- addreg(head, dir->d_name, 0);
+ addreg(head, dir->d_name, level);
}
+ closedir(d);
}
void getfile(regfile * head, const char * parent)
{
init(head);
-
extractContent(head, parent, 0);
}
-
diff --git a/c/tree/main.c b/c/tree/main.c
index b4b3374..073167e 100644
--- a/c/tree/main.c
+++ b/c/tree/main.c
@@ -11,7 +11,7 @@ void printChild(const regfile * head)
regfile * scan = head->next;
while (scan != NULL) {
- printf("%s\tlevel: %d\tname length: %u\tfile or dir: ",scan->node->text,
+ printf("%s\tlevel: %d\tname length: %lu\tfile or dir: ",scan->node->text,
scan->node->level, scan->node->len);
if (scan->node->fod)
printf("dir\n");
diff --git a/codecrafters/codecrafters-docker-c b/codecrafters/codecrafters-docker-c
new file mode 160000
+Subproject e7dcf979dd7a7554e7b14a5c90faab403b082c6
diff --git a/codecrafters/codecrafters-grep-rust b/codecrafters/codecrafters-grep-rust
new file mode 160000
+Subproject f70f16848ddddf62b3f89cfe9d7e3970e0ca2af
diff --git a/lua/6.lua b/lua/6.lua
new file mode 100644
index 0000000..34df3d3
--- /dev/null
+++ b/lua/6.lua
@@ -0,0 +1,61 @@
+--[[print(json.encode((t['data'][2]['name'])))
+for d,v in pairs(t) do
+ if type(v) == "table" then
+ print (d, ins(v))
+ else
+ print(d,v)
+ end
+end]]
+
+require 'socket'
+local json = require 'json'
+local https = require 'ssl.https'
+
+local record = "["
+
+local id = {35545979,1305487,30170448,27119156,26844438,26359270,1296339,30183610,27185036,7051830,10535568,10562987,1652592,26835471,26235354,26584183,25862357,
+ 25826612,23232876,10590706,6558062,3016187,25815008,27074316,1296078,20438964,1303139,1889152,1309160,1300064,1300498,1293353,10440138,1304643,1293702,
+ 1292523,1297995,2051007,1433330,26394152,7054604,3610047,2146991,1794171,1457217,2353023,27163278,3041264,26416603,3649049,26266085,26607693,1851857,3057368,
+ 27098632,6534248,3168101,1292225,1292226,1296102,26804147,3025375,25820460,1866473,10741834,7065154,6390823,6560058,3231742,1866479,2138838,1866471,3066739,
+ 1866475,1432146,26100958,26794435,3364223,1292224,1292063,26865694,26792604,7051471,25851657,26899726,30377729,10491666,27140017,10428503,6058418,10801894,
+ 26746536,26677623,3402131,26758347,26974705,10437826,2330826,4901698,25785220,4728562,10480956,20391245,26944371,26312622,25861694,26597755,20378778,4960070,
+ 10763906,26655965,25774763,25772493,30276444,4893988,2330821,4176578,27079297,19944226,26669291,26752113,6886510,27157689,5446211,3538051,25901415,26844127,
+ 4019449,4935090,23229638,27085551,21371652,4848113,10558424,10558423,26087258,20438714,26708200,26035319,26087257,3993682,27081136,26969673,27094897,25846907,
+ 27015988,2249531,3251306,20266747,4202090,26746533,27045615,23750688,21348026,3681349,4291876,27047873,1810517,26974053,10759936,30158971,4074292,1800597,4223466,
+ 26877406,26575153,20514713,26282460,10877415,6894811,26708698,25850705,10001418,3908423,6984051,2357701,5153329,1827955,26596486,2279152,26094129,27072327,27110363,
+ 30353357,2326676,5397537,4848701,20514947,1316693,1305306,1305065,6985810,1300267,26799731,26147706,1308820,25958717,4305436,20645098,6010171,1300883,1300566,1304677,
+ 1299765,1295340,2998373,1296201,1305355,1298644,3602084,11443314,4767216,1307389,1299680,3286528,3286531,3286549,3286536,3286548,3286547,3286538,3286543,3286552,1302090,
+ 2213591,1297223,1297863,6395245,1297747,1835843,1293088,4915857,1329936,1297518,10574622,4807924,1302958,1393859,1309055,7064681,1296996,2997076,1291544,27063403,25796222,
+ 11584024,3269068,1306785,6007281,3731581,26788667,20274039,3387546,25782633,2357707,2357711,4914468,4907844,1793912,2357703,4202982,1439579,1958667,1926790,5322572,2286642,
+ 1291581,1457957,2357162,1458905,1458907,1437342,1291586,1418019,2028585,1307739,10727641,26336252,1298525,1401533,1292484,3068206,27109679,25920885,25750923,10455629,6522269,
+ 3986493,4051753,2998270,1458895,1458898,1458891,1438591,1458904,1458892,1458889,1458909,1458906,1458903,1458890,1458893,1458894,1457926,1458896,1458910,1458908,1458902,1458900,
+ 1458897,1458901,3154822,25928048,2977870,11584309,1865943,26839466,26527993,27069070,6738701,25769362,24859558,4896303,3755531,26884354,27107140,27193043,6873143,25662337,
+ 6517421,3071441,3005875,26266893,1293013,1308779,24405378,27622447,22766027,4160540,2993217,1295280,1301445,1994876,11810348,3178770,1309201,26309788,1309043,3771562,1300868,
+ 25790761,25726614,6532822,3041294,1482911,1308752,1306809,26742730,1294388,1308772,1292867,1422106,1302753,1304642,1292624,1297909,25723583,1306160,4212172,1859036,1394968,
+ 1294693,1309071,1308751,1305903,26004132,25995508,21349345,1421884,1291566,1291936,25834500,1483507,4246125,1381964,20470074,2043546,25986180,4920389,1292270,1291543,1291844,
+ 1302467,25895901,1959195,1937946,1395091,1291578,26683290,1293318,26325320,1292401,1907966,1291579,11026735,1306249,3287562,5989818,3011235,25814707,1293359,6791750,1291838,
+ 1959877,1291585,1865703,1316510,25814705,21318488,1302425,1294371,1292849,1295038,1291843,1301753,1309046,20495023,1293172,1308807,1299398,26387939,1291583,3319755,1849031,
+ 25662329,1291560,1889243,1292213,1292064,1292001,3793023,3011091,3541415,1292722,1292720,1295644,1291546,1292052,1291561,2129039,1652618,1307442,2132930,1304899,6537500,
+ 4286017,26260853,23761370,3227410,1418192,1315574,6311303,1298070,1432639,2336783,1764796,1297131,1820145,3642835,1309060,2336785,1309101}
+
+local score = {4,5,4,4,4,5,4,3,4,3,4,4,1,3,,,,,,,,5,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,3,3,3,3,3,4,4,3,2,4,4,4,4,5,5,5,4,3,4,5,3,3,,,,,,,,,,,,,,,3,4,4,5,5,4,3,5,3,3,4,3,3,3,3,5,4,3,4,3,2,5,4,4,2,3,3,3,2,3,5,3,3,3,3,3,3,3,3,3,4,5,3,3,4,4,5,3,5,5,3,3,3,4,4,5,5,3,3,3,4,3,3,5,4,5,5,3,3,4,4,3,4,4,4,2,3,5,5,5,4,5,5,5,3,4,5,5,5,4,3,4,4,4,5,4,5,4,4,3,3,3,3,3,4,3,4,3,4,4,5,5,3,3,2,3,5,5,5,4,4,4,4,4,5,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,4,3,4,4,5,4,3,5,4,4,4,3,4,4,5,4,5,4,4,4,5,4,4,4,4,4,5,3,3,4,3,4,4,4,4,4,4,5,5,4,4,5,5,5,5,5,5,5,4,4,4,5,5,3,3,3,3,3,3,4,4,5,5,5,5,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,3,3,3,4,3,4,4,3,3,4,4,4,5,3,4,3,,4,4,4,4,4,4,4,4,4,4,4,3,4,4,4,1,4,5,4,4,4,4,4,4,4,4,4,4,4,5,5,4,4,4,2,3,4,5,5,5,4,4,3,4,4,5,3,3,5,5,3,5,5,5,5,5,5,5,5,5,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,5,5,5,5,5,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,5,5,4,5,5,5,5,3,4,4,4,4,4,3,4,4,4,5,4,5,3,4,4,4,5,3,5,4,5}
+local comment = {2021-07-31 12:04:34,2020-08-25 10:56:21,2020-08-25 10:55:20,2019-11-06 20:46:07,2019-11-06 20:45:59,2019-11-06 20:45:51,2019-11-06 20:45:32,2019-10-18 14:14:33,2019-10-18 14:14:19,2019-10-06 23:43:22,2019-10-02 23:46:03,2019-10-02 23:45:18,2019-09-28 20:49:59,2019-09-27 21:46:41,2019-09-21 22:58:36,2019-09-21 22:58:35,2019-09-21 22:58:33,2019-09-21 22:58:32,2019-09-21 22:58:31,2019-09-21 22:58:30,2019-09-21 22:58:28,2019-09-21 22:58:19,2019-09-21 22:44:41,2019-09-21 22:44:31,2019-09-09 17:09:44,2019-09-09 17:08:07,2019-09-03 18:35:14,2019-09-03 18:34:52,2019-09-03 17:33:14,2019-09-01 00:09:22,2019-09-01 00:09:03,2019-09-01 00:07:41,2019-09-01 00:06:03,2019-09-01 00:05:52,2019-09-01 00:05:29,2019-09-01 00:05:01,2019-09-01 00:03:35,2019-09-01 00:03:04,2019-09-01 00:02:57,2019-09-01 00:02:18,2019-09-01 00:01:56,2019-09-01 00:01:50,2019-09-01 00:01:25,2019-09-01 00:01:03,2019-09-01 00:00:35,2019-09-01 00:00:20,2019-08-31 23:59:06,2019-08-31 23:58:08,2019-08-31 23:57:59,2019-08-31 23:56:59,2019-08-31 23:56:03,2019-08-31 23:55:23,2019-08-31 23:54:57,2019-08-31 18:27:12,2019-08-31 18:25:20,2019-08-28 14:03:34,2019-08-23 12:30:41,2019-08-22 19:40:17,2019-08-22 19:39:42,2019-08-19 22:26:51,2019-08-07 00:30:55,2019-08-07 00:30:02,2019-08-07 00:30:01,2019-08-07 00:29:59,2019-08-07 00:29:58,2019-08-07 00:29:56,2019-08-07 00:29:53,2019-08-07 00:29:52,2019-08-07 00:29:49,2019-08-07 00:29:47,2019-08-07 00:29:46,2019-08-07 00:29:45,2019-08-07 00:29:44,2019-08-07 00:29:43,2019-08-07 00:29:40,2019-08-07 00:29:31,2019-07-31 02:19:03,2019-07-28 23:55:37,2019-10-02 23:43:17,2019-07-28 16:32:28,2019-07-26 13:41:42,2019-07-26 13:41:19,2019-07-26 13:40:38,2019-07-26 13:39:50,2019-07-26 13:39:06,2019-07-26 13:37:06,2019-07-26 13:36:59,2019-07-26 13:36:48,2019-07-26 02:09:37,2019-07-26 02:08:20,2019-07-26 02:08:05,2019-07-26 02:05:27,2019-07-26 02:05:09,2019-07-26 02:04:39,2019-07-26 02:03:59,2019-07-26 02:03:15,2019-07-26 02:02:57,2019-07-26 02:02:32,2019-07-26 02:02:17,2019-07-26 02:01:45,2019-07-26 02:00:47,2019-07-26 02:00:19,2019-07-26 01:59:38,2019-07-26 01:58:59,2019-07-26 01:58:10,2019-07-26 01:57:55,2019-07-26 01:57:03,2019-07-26 01:56:50,2019-07-26 01:56:21,2019-07-26 01:55:44,2019-07-26 01:54:57,2019-07-26 01:54:32,2019-07-26 01:54:23,2019-07-26 01:54:09,2019-07-26 01:53:59,2019-07-26 01:53:13,2019-07-26 01:53:02,2019-07-26 01:52:47,2019-07-26 01:52:24,2019-07-26 01:52:07,2019-07-26 01:51:56,2019-07-26 01:51:46,2019-07-26 01:51:33,2019-07-26 01:50:50,2019-07-26 01:49:09,2019-07-26 01:48:43,2019-07-26 01:47:46,2019-07-26 01:47:29,2019-07-26 01:47:17,2019-07-26 01:47:02,2019-07-26 01:46:45,2019-07-26 01:46:31,2019-07-26 01:45:55,2019-07-26 01:45:24,2019-07-26 01:45:14,2019-07-26 01:44:54,2019-07-26 01:44:35,2019-08-22 20:51:41,2019-07-26 01:43:53,2019-07-26 01:43:12,2019-07-26 01:42:46,2019-07-26 01:42:16,2019-07-26 01:42:05,2019-07-26 01:41:19,2019-07-26 01:40:53,2019-07-26 01:39:49,2019-07-26 01:39:34,2019-07-26 01:39:21,2019-07-26 01:38:54,2019-07-26 01:38:25,2019-07-26 01:38:14,2019-07-26 01:36:36,2019-07-26 01:35:30,2019-07-26 01:35:17,2019-07-26 01:34:23,2019-07-26 01:33:52,2019-07-26 01:33:00,2019-07-26 01:32:35,2019-07-26 01:32:27,2019-07-26 01:31:58,2019-07-26 01:31:47,2019-07-26 01:31:20,2019-07-26 01:31:10,2019-07-26 01:30:58,2019-07-26 01:30:40,2019-07-26 01:30:25,2019-07-26 01:30:14,2019-07-26 01:30:05,2019-07-26 01:29:48,2019-07-26 01:29:31,2019-07-26 01:29:11,2019-07-26 01:28:52,2019-07-26 01:28:26,2019-07-26 01:28:16,2019-07-26 01:28:01,2019-07-26 01:27:41,2019-07-26 01:27:31,2019-07-26 01:27:21,2019-07-26 01:27:07,2019-07-26 01:26:59,2019-07-26 01:26:50,2019-07-26 01:26:35,2019-07-26 01:26:22,2019-07-26 01:26:12,2019-07-26 01:25:30,2019-07-26 01:25:16,2019-07-26 01:24:45,2019-07-26 01:23:53,2019-07-25 01:39:08,2019-07-25 00:01:25,2019-07-22 00:11:22,2019-07-21 22:35:44,2020-08-25 10:55:06,2019-08-31 17:36:50,2019-07-20 22:14:45,2019-07-20 22:14:37,2020-11-17 15:33:14,2019-07-20 22:10:49,2019-07-20 22:10:15,2019-07-19 23:23:20,2019-07-14 16:01:57,2019-07-14 16:01:10,2019-07-14 16:00:58,2019-07-14 16:00:40,2019-07-14 16:00:10,2019-07-14 15:59:59,2019-07-14 15:59:47,2019-07-14 15:59:19,2019-07-14 15:59:04,2019-07-14 15:58:51,2019-07-14 15:58:41,2019-07-14 15:58:29,2019-07-14 15:58:19,2019-07-14 15:58:07,2019-07-14 15:57:38,2019-07-14 15:57:23,2019-07-14 15:57:11,2019-07-14 15:56:58,2019-07-14 15:56:46,2019-07-14 15:56:36,2019-07-14 15:56:26,2019-07-14 15:56:16,2019-07-14 15:56:08,2019-07-14 15:55:57,2019-07-14 15:55:47,2019-07-14 15:55:28,2019-07-14 15:55:15,2019-07-14 15:55:06,2019-07-14 15:54:54,2019-07-14 15:54:40,2019-07-14 15:54:30,2019-07-14 15:54:21,2019-07-14 15:54:07,2019-07-14 15:53:52,2019-07-14 15:53:24,2019-07-14 15:53:13,2019-07-14 15:52:54,2019-07-14 15:52:37,2019-07-14 15:52:15,2019-07-14 15:51:54,2019-07-14 15:51:42,2019-07-14 15:51:18,2019-07-14 15:49:56,2019-07-14 15:49:29,2019-07-14 15:49:13,2019-07-14 15:48:43,2019-07-14 15:48:14,2019-07-14 15:47:57,2019-07-14 15:47:44,2019-07-14 15:47:21,2019-07-14 15:46:57,2019-07-14 15:46:49,2019-07-14 15:46:31,2019-07-14 15:46:14,2019-07-14 15:45:47,2019-07-14 15:45:25,2019-07-14 15:45:13,2019-07-14 15:45:03,2019-07-14 15:44:49,2019-07-14 15:44:29,2019-07-14 15:44:00,2019-07-14 15:43:42,2019-07-14 15:43:22,2019-07-14 15:43:14,2019-07-14 15:43:03,2019-07-14 15:42:49,2019-07-14 15:42:14,2019-07-14 15:41:53,2019-07-14 15:41:46,2019-07-14 15:41:35,2019-07-14 15:41:25,2019-07-14 15:41:13,2019-07-14 15:41:04,2019-07-14 15:40:52,2019-07-14 15:40:05,2019-07-14 15:39:59,2019-07-14 15:39:33,2019-07-14 15:39:25,2019-07-14 15:39:17,2019-07-14 15:39:11,2019-07-14 15:39:01,2019-07-14 15:38:51,2019-07-14 15:37:38,2019-07-14 15:36:47,2019-07-14 15:36:32,2019-07-14 15:36:24,2019-07-14 15:36:18,2019-07-14 15:36:11,2019-07-14 15:35:24,2019-07-14 15:35:16,2019-07-14 15:33:54,2019-07-13 21:53:04,2019-07-13 21:52:46,2019-07-13 21:47:58,2019-07-13 21:47:00,2019-07-13 21:46:38,2019-07-13 21:46:07,2019-07-13 21:45:48,2019-07-13 21:44:38,2019-07-13 21:44:14,2019-07-13 21:43:56,2019-07-13 21:41:59,2019-07-13 21:40:49,2019-07-13 21:39:05,2019-07-13 21:38:27,2019-07-13 21:37:38,2019-07-13 21:35:51,2019-07-13 21:35:34,2019-07-13 21:35:21,2019-07-13 21:34:29,2019-07-13 21:34:05,2019-07-13 21:33:46,2019-07-13 21:33:29,2019-07-13 21:33:04,2019-07-13 21:32:50,2019-07-13 21:32:20,2019-07-13 21:32:06,2019-07-13 21:31:47,2019-07-13 21:31:24,2019-07-13 21:31:03,2019-07-13 21:30:40,2019-07-13 21:30:23,2019-07-13 21:29:56,2019-07-13 21:29:28,2019-07-13 21:27:38,2019-07-13 03:01:32,2019-07-13 03:01:02,2019-07-13 03:00:51,2019-07-13 03:00:08,2019-07-13 03:00:00,2019-07-13 02:58:38,2019-07-13 02:58:23,2019-07-13 02:58:07,2019-07-13 02:57:53,2019-07-13 02:57:38,2019-07-13 02:56:25,2019-07-13 02:54:40,2019-07-13 02:53:25,2019-07-13 02:51:30,2019-07-13 02:50:42,2019-07-13 02:48:30,2019-07-13 02:48:19,2019-07-13 02:44:09,2019-07-13 02:44:02,2019-07-13 02:43:37,2019-07-13 02:43:27,2019-07-13 02:42:39,2019-07-13 02:42:28,2019-07-13 02:41:41,2019-07-13 02:41:18,2019-07-13 02:40:11,2019-07-13 02:39:56,2019-07-13 02:38:53,2019-07-13 02:37:25,2019-07-13 02:37:06,2019-07-13 02:36:56,2019-07-13 02:36:44,2019-07-13 02:35:30,2019-07-13 02:34:51,2019-07-13 02:34:18,2019-07-13 02:34:05,2019-07-13 02:33:56,2019-07-13 02:33:44,2019-07-13 02:33:33,2019-07-13 02:33:14,2019-07-13 02:32:55,2019-07-13 02:32:34,2019-07-13 02:32:23,2019-07-13 02:32:08,2019-07-13 02:31:57,2019-07-13 02:31:08,2019-07-13 02:30:51,2019-07-13 02:30:09,2019-07-13 02:29:48,2019-07-13 02:29:25,2019-07-13 02:28:30,2019-07-13 02:28:21,2019-07-13 02:28:14,2019-07-13 02:26:55,2019-07-13 02:26:21,2019-07-13 02:26:09,2019-07-13 02:25:36,2019-07-13 02:25:15,2019-07-13 02:25:01,2019-07-13 02:24:52,2019-07-13 02:24:34,2019-07-13 02:21:48,2019-07-13 02:21:30,2019-07-13 02:20:56,2019-07-13 02:20:37,2019-07-13 02:20:15,2019-07-13 02:19:42,2019-07-13 02:19:03,2019-07-13 02:18:50,2019-07-13 02:18:32,2019-07-13 02:18:13,2019-07-13 02:17:56,2019-07-13 02:17:40,2019-07-13 02:16:09,2019-07-13 02:14:50,2019-07-13 02:14:35,2019-08-07 00:28:42,2019-07-13 02:14:13,2019-07-13 02:13:47,2019-07-13 02:13:39,2019-07-13 02:13:30,2019-07-13 02:13:10,2019-07-13 02:12:57,2019-07-13 02:12:34,2019-07-13 02:12:24,2019-07-13 02:12:16,2019-07-13 02:12:02,2019-07-13 02:12:01,2019-07-13 02:11:59,2019-07-13 02:11:44,2019-07-13 02:11:26,2019-07-13 02:11:10,2019-07-13 02:10:58,2019-07-13 02:10:47,2019-07-13 02:10:35,2019-07-13 02:10:23,2019-07-13 02:09:31,2019-07-13 02:09:08,2019-07-13 02:08:56,2019-07-13 02:08:04,2019-07-13 02:07:55,2019-07-13 02:07:38,2019-07-13 02:07:29,2019-07-13 02:07:06,2019-07-13 02:06:49,2019-07-13 02:06:33,2019-07-13 02:06:18,2019-07-13 02:06:02,2019-07-13 02:05:48,2019-07-13 02:05:39,2019-07-13 02:05:26,2019-07-13 02:05:14,2019-07-13 02:05:06,2019-07-13 02:04:56,2019-07-13 02:04:35,2019-07-13 02:04:21,2019-07-13 02:04:10,2019-07-13 02:04:00,2019-07-13 02:03:45,2019-07-13 02:03:34,2019-07-13 02:03:26,2019-07-13 02:03:13,2019-07-13 02:02:23,2019-07-13 02:01:49,2019-07-13 02:01:07,2019-07-13 02:00:32,2019-07-13 02:00:10,2019-07-13 02:00:00,2019-07-13 01:59:53,2019-07-13 01:59:44,2019-07-13 01:59:32,2019-07-13 01:59:19,2019-07-13 01:59:08,2019-07-13 01:58:23,2019-07-13 01:58:11,2019-07-13 01:58:01,2019-07-13 01:57:49,2019-07-13 01:57:24,2019-07-13 01:56:55,2019-07-13 01:54:37,2019-07-13 01:54:23,2019-07-13 01:54:12,2019-07-13 01:53:45,2019-07-13 01:53:29,2019-07-13 01:53:11,2019-07-13 01:53:00,2019-07-13 01:51:28}
+
+local open = io.open
+local file = open ("./a.json","rb")
+if not file then return nil end
+local jsonString = file:read "*a"
+file:close()
+
+local ins = require 'inspect'
+local t = json.decode(jsonString)
+record = record .. "{title: " .. t['originalName'] .. ", "
+record = record .. "Publishing: "..t['dateReleased'] ..", "
+record = record .. "Country: " .. t['data'][2]['country']:gsub('[%p]','') ..", "
+record = record .. "Genre: " .. t['data'][2]['genre']:gsub('& ',''):gsub('/',' ') .. ', '
+record = record .. "Director: " .. t['director'][1]['data'][2]['name'] .. ', '
+print(record)
+
+function getjson(id)
+ local body, code = https.request("https://api.wmdb.tv/movie/api?id="..id)
+end
diff --git a/rust/theBook/chapter-10-generic-types-traits-lifetimes/generic-type/Cargo.toml b/rust/theBook/chapter-10-generic-types-traits-lifetimes/generic-type/Cargo.toml
new file mode 100644
index 0000000..8f1e556
--- /dev/null
+++ b/rust/theBook/chapter-10-generic-types-traits-lifetimes/generic-type/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "generic-type"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/rust/theBook/chapter-10-generic-types-traits-lifetimes/generic-type/src/main.rs b/rust/theBook/chapter-10-generic-types-traits-lifetimes/generic-type/src/main.rs
new file mode 100644
index 0000000..8a3ef34
--- /dev/null
+++ b/rust/theBook/chapter-10-generic-types-traits-lifetimes/generic-type/src/main.rs
@@ -0,0 +1,45 @@
+#[derive(Debug)]
+struct Point<T, U> {
+ x: T,
+ y: U,
+}
+
+// T and U are declared for impl for it goes with struct
+impl<T, U> Point<T,U> {
+ fn new(value: T, v: U) -> Self {
+ Point {x: value, y: v}
+ }
+
+ // X1 and Y1 are only relavent to method mixup
+ fn mixup<X1, Y1>(self, other: Point<X1, Y1>) -> Point<T,Y1> {
+ Point {x: self.x, y: other.y}
+ }
+}
+
+fn largest<T: std::cmp::PartialOrd>(list: &[T]) -> &T {
+ let mut largest = &list[0];
+
+ for item in list {
+ if largest < item {
+ largest = item;
+ }
+ }
+ largest
+}
+
+fn main() {
+ let x = [1,3,5,7,9];
+ let y = ['a','b','c','d','e'];
+
+ let result = largest(&x);
+ println!("{result}");
+
+ let result = largest(&y);
+ println!("{result}");
+
+ let result = Point::new(3.5,7);
+ println!("{},{}",result.x, result.y);
+
+ let result = result.mixup(Point::new("hello",'c'));
+ println!("{},{}",result.x, result.y);
+}
diff --git a/rust/theBook/chapter-10-generic-types-traits-lifetimes/non-generic-largest.rs b/rust/theBook/chapter-10-generic-types-traits-lifetimes/non-generic-largest.rs
new file mode 100644
index 0000000..149561e
--- /dev/null
+++ b/rust/theBook/chapter-10-generic-types-traits-lifetimes/non-generic-largest.rs
@@ -0,0 +1,34 @@
+fn largest_i32(list: &[i32]) -> &i32 {
+ let mut largest = &list[0];
+
+ for item in list {
+ if largest < item {
+ largest = item;
+ }
+ }
+
+ largest
+}
+
+fn largest_char(list: &[char]) -> &char {
+ let mut largest = &list[0];
+
+ for item in list {
+ if largest < item {
+ largest = item;
+ }
+ }
+
+ largest
+}
+
+fn main() {
+ let l1 = [1,3,5,7,9];
+
+ let l2 = ['a','b','c','d','e'];
+
+ let m1 = largest_i32(&l1);
+ let m2 = largest_char(&l2);
+
+ println!("{m1}, {m2}");
+}
diff --git a/rust/theBook/chapter-10-generic-types-traits-lifetimes/traits/Cargo.toml b/rust/theBook/chapter-10-generic-types-traits-lifetimes/traits/Cargo.toml
new file mode 100644
index 0000000..460f45f
--- /dev/null
+++ b/rust/theBook/chapter-10-generic-types-traits-lifetimes/traits/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "traits"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/rust/theBook/chapter-10-generic-types-traits-lifetimes/traits/src/lib.rs b/rust/theBook/chapter-10-generic-types-traits-lifetimes/traits/src/lib.rs
new file mode 100644
index 0000000..45c93c8
--- /dev/null
+++ b/rust/theBook/chapter-10-generic-types-traits-lifetimes/traits/src/lib.rs
@@ -0,0 +1,29 @@
+pub trait Summary {
+ fn summarize (&self) -> String;
+}
+
+pub struct NewsArticle {
+ pub author: String,
+ pub headline: String,
+ pub location: String,
+ pub content: String,
+}
+
+impl Summary for NewsArticle {
+ fn summarize(&self) -> String { // return String ownership. &self means self: &Self
+ format!("{} by {} ({})", self.headline, self.author, self.location)
+ }
+}
+
+pub struct Tweet {
+ pub username: String,
+ pub content: String,
+ pub retweet: bool,
+ pub reply: bool,
+}
+
+impl Summary for Tweet {
+ fn summarize(&self) -> String { // &Self is the type owns impl
+ format!("{}: {}",self.username, self.content)
+ }
+}
diff --git a/rust/theBook/chapter-10-generic-types-traits-lifetimes/traits/src/main.rs b/rust/theBook/chapter-10-generic-types-traits-lifetimes/traits/src/main.rs
new file mode 100644
index 0000000..f0229a0
--- /dev/null
+++ b/rust/theBook/chapter-10-generic-types-traits-lifetimes/traits/src/main.rs
@@ -0,0 +1,23 @@
+use traits::{Tweet, Summary, NewsArticle};
+
+fn main() {
+ let tweet = Tweet {
+ username: String::from("horse_ebook"),
+ content: String::from(
+ "of course, as you probably already know, people."
+ ),
+ reply: false,
+ retweet: false,
+ };
+
+ println!("1 new tweet: {}", tweet.summarize());
+
+ let article = NewsArticle {
+ author: String::from("garhve"),
+ headline: String::from("how to die"),
+ location: String:: from("United Kingdom"),
+ content: String::from("This is how we gonna die"),
+ };
+
+ println!("1 new article: {}",article.summarize());
+}