panddu 1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
panddu/__init__.py ADDED
@@ -0,0 +1,342 @@
1
+ """Offline developer references."""
2
+
3
+ import re
4
+ import textwrap
5
+
6
+ __version__ = "1.1"
7
+
8
+
9
+ class _Snippet(str):
10
+ """A string that displays as formatted text in an interactive console."""
11
+
12
+ def __repr__(self) -> str:
13
+ print(str(self))
14
+ return ""
15
+
16
+
17
+ def _snippet(value: str) -> _Snippet:
18
+ text = textwrap.dedent(value).strip()
19
+ text = re.sub(r"\n{3,}", "\n\n", text)
20
+ return _Snippet(text)
21
+
22
+
23
+ css = _snippet(
24
+ """
25
+ .topbar {
26
+ display: flex;
27
+ justify-content: space-between;
28
+ align-items: center;
29
+ }
30
+
31
+ .menu {
32
+ display: flex;
33
+ flex-direction: row;
34
+ gap: 12px;
35
+ }
36
+
37
+ .menu a {
38
+ text-decoration: none;
39
+ }
40
+
41
+ .photos {
42
+ display: grid;
43
+ grid-template-columns: repeat(4, 1fr);
44
+ gap: 10px;
45
+ }
46
+
47
+ .wide {
48
+ grid-column: span 2;
49
+ }
50
+
51
+ .profile {
52
+ border: 2px solid #999;
53
+ border-radius: 12px;
54
+ padding: 24px;
55
+ margin: 10px;
56
+ }
57
+
58
+ .profile:hover {
59
+ background-color: #eef6ff;
60
+ }
61
+
62
+ @media (max-width: 768px) {
63
+ .profile {
64
+ width: 100%;
65
+ }
66
+ }
67
+ """
68
+ )
69
+
70
+ django = _snippet(
71
+ """
72
+ class Booking(models.Model):
73
+ guest = models.ForeignKey(User, on_delete=models.CASCADE)
74
+ room = models.CharField(max_length=50)
75
+ amount = models.DecimalField(max_digits=10, decimal_places=2)
76
+ booked_on = models.DateTimeField(auto_now_add=True)
77
+
78
+ def booking_list(request):
79
+ bookings = Booking.objects.filter(confirmed=True)
80
+ return render(request, "bookings/list.html", {"bookings": bookings})
81
+
82
+ def booking_create(request):
83
+ if request.method == "POST":
84
+ Booking.objects.create(
85
+ room=request.POST["room"],
86
+ amount=request.POST["amount"],
87
+ )
88
+ return redirect("booking-list")
89
+ return render(request, "bookings/form.html")
90
+
91
+ @login_required
92
+ def profile(request):
93
+ return render(request, "profile.html")
94
+
95
+ # project/urls.py
96
+ from django.urls import include, path
97
+
98
+ urlpatterns = [
99
+ path("catalog/", include("catalog.urls")),
100
+ ]
101
+
102
+ # catalog/urls.py
103
+ urlpatterns = [
104
+ path("course/<int:pk>/", views.course_detail, name="course-detail"),
105
+ ]
106
+
107
+ # catalog/views.py
108
+ def course_detail(request, pk):
109
+ course = get_object_or_404(Course, pk=pk)
110
+ previous = request.session.get("recent_course")
111
+ request.session["recent_course"] = course.pk
112
+ return render(
113
+ request,
114
+ "catalog/detail.html",
115
+ {"course": course, "previous": previous},
116
+ )
117
+
118
+ def signout_view(request):
119
+ logout(request)
120
+ return redirect("login")
121
+
122
+ <!-- catalog/detail.html -->
123
+ {% extends "layout.html" %}
124
+ {% block content %}
125
+ <h1>{{ course.title }}</h1>
126
+ {% if course.is_open %}
127
+ <p>Admissions open</p>
128
+ {% endif %}
129
+ <form method="post">{% csrf_token %}<button>Enroll</button></form>
130
+ {% endblock %}
131
+
132
+ # serializers.py
133
+ class BookSerializer(serializers.ModelSerializer):
134
+ class Meta:
135
+ model = Book
136
+ fields = "__all__"
137
+
138
+ # views.py
139
+ class BookViewSet(viewsets.ModelViewSet):
140
+ queryset = Book.objects.all()
141
+ serializer_class = BookSerializer
142
+ permission_classes = [IsAuthenticated]
143
+
144
+ # urls.py
145
+ router = routers.DefaultRouter()
146
+ router.register("books", BookViewSet)
147
+ urlpatterns = [path("api/", include(router.urls))]
148
+
149
+ # ml_views.py
150
+ @api_view(["POST"])
151
+ def price_estimate(request):
152
+ inputs = request.data["inputs"]
153
+ output = model.predict([inputs])
154
+ return Response({"estimate": output[0]})
155
+ """
156
+ )
157
+
158
+ docker = _snippet(
159
+ """
160
+ 1. Build an image with tag 2.1 -> `docker build -t sample-api:2.1 .`
161
+ 2. Run httpd:alpine in background, name site, map 3000 to 80 -> `docker run -d --name site -p 3000:80 httpd:alpine`
162
+ 3. Open shell inside site -> `docker exec -it site sh`
163
+ 4. Start Compose services detached and rebuild -> `docker compose up -d --build`
164
+ 5. Tag image for a registry account -> `docker tag sample-api:2.1 example/sample-api:2.1`
165
+ 6. List all containers including stopped -> `docker ps -a`
166
+ 7. Display container logs -> `docker logs api`
167
+ 8. Stop a container -> `docker stop api`
168
+ 9. Create a volume -> `docker volume create appdata`
169
+ 10. Remove Compose services and volumes -> `docker compose down -v`
170
+ 11. Download mysql:8 without running it -> `docker pull mysql:8`
171
+ 12. Run mysql:8 with a password and volume -> `docker run -d --name mysql-db -e MYSQL_ROOT_PASSWORD=change-me -v appdata:/var/lib/mysql mysql:8`
172
+ 13. Show all local images -> `docker images`
173
+ 14. Remove a stopped container -> `docker rm api`
174
+ 15. Delete an image -> `docker rmi sample-api:2.1`
175
+ """
176
+ )
177
+
178
+ git = _snippet(
179
+ """
180
+ 1. Start tracking a project folder -> `git init`
181
+ 2. Stage only index.html -> `git add index.html`
182
+ 3. Commit staged changes -> `git commit -m "Fix footer links"`
183
+ 4. Create and switch to a branch -> `git switch -c feature-page`
184
+ 5. Merge a completed branch into the current branch -> `git merge feature-page`
185
+ 6. Check modified and staged files -> `git status`
186
+ 7. Stage all changed files in the current folder -> `git add .`
187
+ 8. View one-line commit history -> `git log --oneline`
188
+ 9. Clone a repository -> `git clone https://example.com/sample/project.git`
189
+ 10. Push the dev branch to a remote -> `git push upstream dev`
190
+ 11. View unstaged changes -> `git diff`
191
+ 12. Create a branch without switching to it -> `git branch feature-header`
192
+ 13. Add a remote -> `git remote add upstream https://example.com/sample/project.git`
193
+ 14. Fetch and merge the latest dev branch -> `git pull upstream dev`
194
+ 15. Unstage app.js while keeping its edits -> `git restore --staged app.js`
195
+ """
196
+ )
197
+
198
+ html = _snippet(
199
+ """
200
+ <head>
201
+ <meta charset="utf-8">
202
+ <title>Sample Blog</title>
203
+ <script src="app.js" defer></script>
204
+ </head>
205
+ <body>
206
+ <header class="site-header"><h1>Sample Blog</h1></header>
207
+ <form method="post" action="/subscribe">
208
+ <label for="phone">Phone</label>
209
+ <input type="tel" id="phone" name="phone">
210
+ </form>
211
+ </body>
212
+
213
+ <!DOCTYPE html>
214
+ <html lang="en">
215
+ <head>
216
+ <meta name="viewport" content="width=device-width, initial-scale=1">
217
+ <link rel="stylesheet" href="theme.css">
218
+ </head>
219
+ <body>
220
+ <main>
221
+ <h1>Events</h1>
222
+ <img src="banner.jpg" alt="Annual event banner">
223
+ <a href="https://example.com/register" target="_blank">Register now</a>
224
+ </main>
225
+ </body>
226
+ </html>
227
+
228
+ <ul>
229
+ <li><a href="/contact">Contact</a></li>
230
+ </ul>
231
+ <table border="1">
232
+ <thead>
233
+ <tr><th>Subject</th><th>Grade</th></tr>
234
+ </thead>
235
+ <tbody>
236
+ <tr><td colspan="2">Average</td></tr>
237
+ </tbody>
238
+ </table>
239
+ <form action="/signin" method="post">
240
+ <input type="password" name="secret" required>
241
+ <select name="year">
242
+ <option value="fy">First Year</option>
243
+ </select>
244
+ </form>
245
+ """
246
+ )
247
+
248
+ sql = _snippet(
249
+ """
250
+ -- 1. Create product table
251
+ CREATE TABLE product (
252
+ product_id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
253
+ name TEXT NOT NULL CHECK (name <> ''),
254
+ stock INTEGER,
255
+ category_id INTEGER REFERENCES category(category_id)
256
+ );
257
+
258
+ -- 2. Insert a product with stock 25 in category 3
259
+ INSERT INTO product (name, stock, category_id)
260
+ VALUES ('Laptop', 25, 3);
261
+
262
+ -- 3. Show products with stock above 10, highest stock first
263
+ SELECT name, stock
264
+ FROM product
265
+ WHERE stock > 10
266
+ ORDER BY stock DESC;
267
+
268
+ -- 4. Show each product with its category name
269
+ SELECT p.name, c.category_name
270
+ FROM product AS p
271
+ INNER JOIN category AS c
272
+ ON p.category_id = c.category_id;
273
+
274
+ -- 5. Show each category and average stock of its products
275
+ SELECT c.category_id, AVG(p.stock) AS average_stock
276
+ FROM category AS c
277
+ LEFT JOIN product AS p
278
+ ON c.category_id = p.category_id
279
+ GROUP BY c.category_id;
280
+
281
+ -- 6. Create magazine table
282
+ CREATE TABLE magazine (
283
+ magazine_id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
284
+ title TEXT NOT NULL CHECK (title <> ''),
285
+ price NUMERIC(10, 2),
286
+ publisher_id INTEGER REFERENCES publisher(publisher_id)
287
+ );
288
+
289
+ -- 7. Insert a magazine
290
+ INSERT INTO magazine (title, price, publisher_id)
291
+ VALUES ('Sample Magazine', 150.00, 4);
292
+
293
+ -- 8. Increase price by 20 for magazines below 100
294
+ UPDATE magazine
295
+ SET price = price + 20
296
+ WHERE price < 100;
297
+
298
+ -- 9. Delete a magazine by ID
299
+ DELETE FROM magazine
300
+ WHERE magazine_id = 12;
301
+
302
+ -- 10. Show publisher name and number of magazines
303
+ SELECT p.publisher_name,
304
+ COUNT(m.magazine_id) AS magazine_count
305
+ FROM publisher AS p
306
+ LEFT JOIN magazine AS m
307
+ ON p.publisher_id = m.publisher_id
308
+ GROUP BY p.publisher_id, p.publisher_name;
309
+
310
+ -- 11. Create customer table
311
+ CREATE TABLE customer (
312
+ cust_id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
313
+ name TEXT NOT NULL CHECK (name <> ''),
314
+ balance NUMERIC(12, 2),
315
+ city TEXT
316
+ );
317
+
318
+ -- 12. Add phone column
319
+ ALTER TABLE customer
320
+ ADD COLUMN phone TEXT;
321
+
322
+ -- 13. Filter customers by city and balance
323
+ SELECT *
324
+ FROM customer
325
+ WHERE city = 'Sample City' AND balance > 20000;
326
+
327
+ -- 14. Show each city with customer count
328
+ SELECT city, COUNT(*) AS customer_count
329
+ FROM customer
330
+ GROUP BY city;
331
+
332
+ -- 15. Allow a read-only role to read customer table
333
+ GRANT SELECT ON TABLE customer TO reader;
334
+ """
335
+ )
336
+
337
+ _COMMANDS = ("css", "django", "docker", "git", "html", "sql")
338
+ all = _snippet( # noqa: A001
339
+ "Available commands:\n" + "\n".join(f" pd.{command}" for command in _COMMANDS)
340
+ )
341
+
342
+ __all__ = ["__version__", *_COMMANDS, "all"]
panddu/__init__.pyi ADDED
@@ -0,0 +1,26 @@
1
+ """Type information and autocomplete for panddu."""
2
+
3
+ __version__: str
4
+
5
+ css: str
6
+ """CSS reference snippets."""
7
+
8
+ django: str
9
+ """Django reference snippets."""
10
+
11
+ docker: str
12
+ """Docker command reference."""
13
+
14
+ git: str
15
+ """Git command reference."""
16
+
17
+ html: str
18
+ """HTML reference snippets."""
19
+
20
+ sql: str
21
+ """SQL reference snippets."""
22
+
23
+ all: str
24
+ """Display all available commands."""
25
+
26
+ __all__: list[str]
panddu/py.typed ADDED
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,5 @@
1
+ Metadata-Version: 2.4
2
+ Name: panddu
3
+ Version: 1.1
4
+ Summary: -
5
+ Requires-Python: >=3.8
@@ -0,0 +1,7 @@
1
+ panddu/__init__.py,sha256=zE2fUCTADNxH4NUZ-VPE45UEKfkiGaAvKqtFOR4WlJ4,10341
2
+ panddu/__init__.pyi,sha256=PhgZV2mjnKdc85YLfpJvhHIyJKp6wKVlkEJq31xWwe8,416
3
+ panddu/py.typed,sha256=4W8VliAYUP1KY2gLJ_YDy2TmcXYVm-PY7XikQD_bFwA,2
4
+ panddu-1.1.dist-info/METADATA,sha256=SfJYOQulw4I9As2EnGUt3YdWget64uYTtdG1Xguo2m8,87
5
+ panddu-1.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
6
+ panddu-1.1.dist-info/top_level.txt,sha256=t5QZsi1fysmWfJ0mGYaoMy78TucSZKoRNoK874HKyDo,7
7
+ panddu-1.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ panddu