Skip to content

Commit

Permalink
CI run: make.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdoe authored and actions-user committed Nov 13, 2023
1 parent 66e6fd0 commit 6441df1
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 0 deletions.
110 changes: 110 additions & 0 deletions book.md
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,8 @@ Sometimes material incentives are also very helpful, e.g. a promise 5$ gift card

[day-365 area](#day-365-area)

[day-366 json](#day-366-json)

## [DAY-0] The Computer

All modern computers(laptops, phones, pc master race rgb monsters, etc) have somewhat similar components: Processor, Memory, Video Card, Disk and USB controller, WiFi card etc. Some of them are in one single chip and you cant even see them anymore, but they are there. For example there are chips that have Processor and Video Card together. The term for processor is actually CPU - Central processing unit, but we called it processors when we were kids and it kind of make sense, since it processes stuff.
Expand Down Expand Up @@ -26211,4 +26213,112 @@ elif ask == '3':
print(result)
```

## [DAY-366] json


> the last 1-2 weeks we were doing ad-hoc small json programs, just serializing and deserializing some state, those are just some of the programs she made



make user.json file

```
{
"name": "Jackie",
"favoriteNumber": 14,
"IsProgrammer": true,
"hobbies": ["learning","volleybal"],
"objects": [{"name": "Defalco"},{"idol": "Defalco"}]

}
```

load it and get some data from the inside objects

```
import json
f=open("user.json","r")
r = f.read()
#print(r)
f.close()

data = json.loads(r)

print(data["objects"][1]["idol"])
```

save some input state:
```
import json
# questions = []

# for i in range(3):
# q = input("q> ")
# a = input("a> ")

# questions.append({"question":q, "answer":a })


# f = open("questions.txt","w")
# f.write(json.dumps(questions)) # serialize
# f.close()

f = open("questions.txt",'r')
data = json.loads(f.read()) # deserialize
f.close()
print(data)
```

some other examples

```
import json

game = {
"board": ['-','-','-','-','-'],
"symbol": 'X'
}
#serialization serial
f = open('tic.json','w')
f.write(json.dumps(game))
f.close()

f = open('tic.json','r')
game = json.loads(f.read())
f.close()
```

another user.json
```
[
{
"BuisnesName": "BigCorperation",
"NumberOfEmbloyes": 2000,
"Ceo": "Jim",
"rating": 4.6
},
{
"BuisnesName": "SmalBUisness",
"numberOfEmployes": 3,
"ceo": null,
"rating": 5
}
]
```

and read it and print something form it

```

import json
f=open("user.json","r")
d = f.read()
print(d)
l = json.loads(d)
f.close()

print(l[0]['rating'])
```

> we made few other small programs on the way, but I didnt write them down. Also we spent fair amount of time going through the network tab in the chrome inspector and looking at various json payloads

8 changes: 8 additions & 0 deletions examples/week-048/015.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "Jackie",
"favoriteNumber": 14,
"IsProgrammer": true,
"hobbies": ["learning","volleybal"],
"objects": [{"name": "Defalco"},{"idol": "Defalco"}]

}
9 changes: 9 additions & 0 deletions examples/week-048/016.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import json
f=open("user.json","r")
r = f.read()
#print(r)
f.close()

data = json.loads(r)

print(data["objects"][1]["idol"])
18 changes: 18 additions & 0 deletions examples/week-048/017.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import json
# questions = []

# for i in range(3):
# q = input("q> ")
# a = input("a> ")

# questions.append({"question":q, "answer":a })


# f = open("questions.txt","w")
# f.write(json.dumps(questions)) # serialize
# f.close()

f = open("questions.txt",'r')
data = json.loads(f.read()) # deserialize
f.close()
print(data)
14 changes: 14 additions & 0 deletions examples/week-048/018.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import json

game = {
"board": ['-','-','-','-','-'],
"symbol": 'X'
}
#serialization serial
f = open('tic.json','w')
f.write(json.dumps(game))
f.close()

f = open('tic.json','r')
game = json.loads(f.read())
f.close()
14 changes: 14 additions & 0 deletions examples/week-048/019.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"BuisnesName": "BigCorperation",
"NumberOfEmbloyes": 2000,
"Ceo": "Jim",
"rating": 4.6
},
{
"BuisnesName": "SmalBUisness",
"numberOfEmployes": 3,
"ceo": null,
"rating": 5
}
]
9 changes: 9 additions & 0 deletions examples/week-048/020.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

import json
f=open("user.json","r")
d = f.read()
print(d)
l = json.loads(d)
f.close()

print(l[0]['rating'])
2 changes: 2 additions & 0 deletions toc.md
Original file line number Diff line number Diff line change
Expand Up @@ -903,3 +903,5 @@
[day-364 misc](#day-364-misc)

[day-365 area](#day-365-area)

[day-366 json](#day-366-json)

0 comments on commit 6441df1

Please sign in to comment.