Skip to content

Commit 686d9f5

Browse files
Merge pull request #40 from E3nviction/main
Added a few python snippets for Sqlite and Json, aswell as a Button snippet for CSS
2 parents 831673e + 65588f5 commit 686d9f5

File tree

2 files changed

+191
-0
lines changed

2 files changed

+191
-0
lines changed

public/data/css.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,35 @@
162162
],
163163
"tags": ["css", "button", "3D", "effect"],
164164
"author": "dostonnabotov"
165+
},
166+
{
167+
"title": "MacOS Button",
168+
"description": "A macOS-like button style, with hover and shading effects.",
169+
"code": [
170+
".button {",
171+
" font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,;",
172+
" background: #0a85ff;",
173+
" color: #fff;",
174+
" padding: 8px 12px;",
175+
" border: none;",
176+
" margin: 4px;",
177+
" border-radius: 10px;",
178+
" cursor: pointer;",
179+
" box-shadow: inset 0 1px 1px #fff2, 0px 2px 3px -2px rgba(0, 0, 0, 0.3) !important; /*This is really performance heavy*/",
180+
" font-size: 14px;",
181+
" display: flex;",
182+
" align-items: center;",
183+
" justify-content: center;",
184+
" text-decoration: none;",
185+
" transition: all 150ms cubic-bezier(0.175, 0.885, 0.32, 1.275);",
186+
"}",
187+
".button:hover {",
188+
" background: #0974ee;",
189+
" color: #fff",
190+
"}"
191+
],
192+
"tags": ["css", "button", "macos", "hover", "transition"],
193+
"author": "e3nviction"
165194
}
166195
]
167196
},

public/data/python.json

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,167 @@
233233
"author": "dostonnabotov"
234234
}
235235
]
236+
},
237+
{
238+
"categoryName": "JSON Manipulation",
239+
"snippets": [
240+
{
241+
"title": "Read JSON File",
242+
"description": "Reads a JSON file and parses its content.",
243+
"code": [
244+
"import json",
245+
"",
246+
"def read_json(filepath):",
247+
" with open(filepath, 'r') as file:",
248+
" return json.load(file)",
249+
"",
250+
"# Usage:",
251+
"data = read_json('data.json')",
252+
"print(data)"
253+
],
254+
"tags": ["python", "json", "file", "read"],
255+
"author": "e3nviction"
256+
},
257+
{
258+
"title": "Write JSON File",
259+
"description": "Writes a dictionary to a JSON file.",
260+
"code": [
261+
"import json",
262+
"",
263+
"def write_json(filepath, data):",
264+
" with open(filepath, 'w') as file:",
265+
" json.dump(data, file, indent=4)",
266+
"",
267+
"# Usage:",
268+
"data = {'name': 'John', 'age': 30}",
269+
"write_json('data.json', data)"
270+
],
271+
"tags": ["python", "json", "file", "write"],
272+
"author": "e3nviction"
273+
}
274+
]
275+
},
276+
{
277+
"categoryName": "SQLite Database",
278+
"snippets": [
279+
{
280+
"title": "Create SQLite Database Table",
281+
"description": "Creates a table in an SQLite database with a dynamic schema.",
282+
"code": [
283+
"import sqlite3",
284+
"",
285+
"def create_table(db_name, table_name, schema):",
286+
" conn = sqlite3.connect(db_name)",
287+
" cursor = conn.cursor()",
288+
" schema_string = ', '.join([f'{col} {dtype}' for col, dtype in schema.items()])",
289+
" cursor.execute(f'''",
290+
" CREATE TABLE IF NOT EXISTS {table_name} (",
291+
" {schema_string}",
292+
" )''')",
293+
" conn.commit()",
294+
" conn.close()",
295+
"",
296+
"# Usage:",
297+
"db_name = 'example.db'",
298+
"table_name = 'users'",
299+
"schema = {",
300+
" 'id': 'INTEGER PRIMARY KEY',",
301+
" 'name': 'TEXT',",
302+
" 'age': 'INTEGER',",
303+
" 'email': 'TEXT'",
304+
"}",
305+
"create_table(db_name, table_name, schema)"
306+
],
307+
"tags": ["python", "sqlite", "database", "table"],
308+
"author": "e3nviction"
309+
},
310+
{
311+
"title": "Insert Data into Sqlite Table",
312+
"description": "Inserts a row into a specified SQLite table using a dictionary of fields and values.",
313+
"code": [
314+
"import sqlite3",
315+
"",
316+
"def insert_into_table(db_path, table_name, data):",
317+
" with sqlite3.connect(db_path) as conn:",
318+
" columns = ', '.join(data.keys())",
319+
" placeholders = ', '.join(['?'] * len(data))",
320+
" sql = f\"INSERT INTO {table_name} ({columns}) VALUES ({placeholders})\"",
321+
" conn.execute(sql, tuple(data.values()))",
322+
" conn.commit()",
323+
"",
324+
"# Usage:",
325+
"db_path = 'example.db'",
326+
"table_name = 'users'",
327+
"data = {",
328+
" 'name': 'John Doe',",
329+
" 'email': 'john@example.com',",
330+
" 'age': 30",
331+
"}",
332+
"insert_into_table(db_path, table_name, data)"
333+
],
334+
"tags": ["python", "sqlite", "database", "utility"],
335+
"author": "e3nviction"
336+
}
337+
]
338+
},
339+
{
340+
"categoryName": "Error Handling",
341+
"snippets": [
342+
{
343+
"title": "Safe Division",
344+
"description": "Performs division with error handling.",
345+
"code": [
346+
"def safe_divide(a, b):",
347+
" try:",
348+
" return a / b",
349+
" except ZeroDivisionError:",
350+
" return 'Cannot divide by zero!'",
351+
"",
352+
"# Usage:",
353+
"print(safe_divide(10, 2)) # Output: 5.0",
354+
"print(safe_divide(10, 0)) # Output: 'Cannot divide by zero!'"
355+
],
356+
"tags": ["python", "error-handling", "division", "utility"],
357+
"author": "e3nviction"
358+
}
359+
]
360+
},
361+
{
362+
"categoryName": "Datetime Utilities",
363+
"snippets": [
364+
{
365+
"title": "Get Current Date and Time String",
366+
"description": "Fetches the current date and time as a formatted string.",
367+
"code": [
368+
"from datetime import datetime",
369+
"",
370+
"def get_current_datetime_string():",
371+
" return datetime.now().strftime('%Y-%m-%d %H:%M:%S')",
372+
"",
373+
"# Usage:",
374+
"print(get_current_datetime_string()) # Output: '2023-01-01 12:00:00'"
375+
],
376+
"tags": ["python", "datetime", "utility"],
377+
"author": "e3nviction"
378+
},
379+
{
380+
"title": "Calculate Date Difference in Milliseconds",
381+
"description": "Calculates the difference between two dates in milliseconds.",
382+
"code": [
383+
"from datetime import datetime",
384+
"",
385+
"def date_difference_in_millis(date1, date2):",
386+
" delta = date2 - date1",
387+
" return delta.total_seconds() * 1000",
388+
"",
389+
"# Usage:",
390+
"d1 = datetime(2023, 1, 1, 12, 0, 0)",
391+
"d2 = datetime(2023, 1, 1, 12, 1, 0)",
392+
"print(date_difference_in_millis(d1, d2))"
393+
],
394+
"tags": ["python", "datetime", "utility"],
395+
"author": "e3nviction"
396+
}
397+
]
236398
}
237399
]

0 commit comments

Comments
 (0)