Skip to content

Commit c74f06f

Browse files
committed
Added Python snippets, aswell as a css snippet
1 parent 600723c commit c74f06f

File tree

2 files changed

+178
-0
lines changed

2 files changed

+178
-0
lines changed

public/data/css.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,35 @@
115115
],
116116
"tags": ["css", "button", "3D", "effect"],
117117
"author": "dostonnabotov"
118+
},
119+
{
120+
"title": "MacOS Button",
121+
"description": "A macOS-like button style, with hover and shading effects.",
122+
"code": [
123+
".button {",
124+
" font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,;",
125+
" background: #0a85ff;",
126+
" color: #fff;",
127+
" padding: 8px 12px;",
128+
" border: none;",
129+
" margin: 4px;",
130+
" border-radius: 10px;",
131+
" cursor: pointer;",
132+
" box-shadow: inset 0 1px 1px #fff2, 0px 2px 3px -2px rgba(0, 0, 0, 0.3) !important; /*This is really performance heavy*/",
133+
" font-size: 14px;",
134+
" display: flex;",
135+
" align-items: center;",
136+
" justify-content: center;",
137+
" text-decoration: none;",
138+
" transition: all 150ms cubic-bezier(0.175, 0.885, 0.32, 1.275);",
139+
"}",
140+
".button:hover {",
141+
" background: #0974ee;",
142+
" color: #fff",
143+
"}"
144+
],
145+
"tags": ["css", "button", "macos", "hover", "transition"],
146+
"author": "enviction"
118147
}
119148
]
120149
},

public/data/python.json

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,154 @@
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.",
282+
"code": [
283+
"import sqlite3",
284+
"",
285+
"def create_table(db_name, table_name):",
286+
" conn = sqlite3.connect(db_name)",
287+
" cursor = conn.cursor()",
288+
" cursor.execute(f'''",
289+
" CREATE TABLE IF NOT EXISTS {table_name} (",
290+
" id INTEGER PRIMARY KEY,",
291+
" name TEXT,",
292+
" age INTEGER",
293+
" )''')",
294+
" conn.commit()",
295+
" conn.close()",
296+
"",
297+
"# Usage:",
298+
"create_table('example.db', 'users')"
299+
],
300+
"tags": ["python", "sqlite", "database", "table"],
301+
"author": "e3nviction"
302+
},
303+
{
304+
"title": "Insert Data into SQLite Table",
305+
"description": "Inserts data into a table in an SQLite database.",
306+
"code": [
307+
"import sqlite3",
308+
"",
309+
"def insert_data(db_name, table_name, name, age):",
310+
" conn = sqlite3.connect(db_name)",
311+
" cursor = conn.cursor()",
312+
" cursor.execute(f'''",
313+
" INSERT INTO {table_name} (name, age) VALUES (?, ?)''',",
314+
" (name, age))",
315+
" conn.commit()",
316+
" conn.close()",
317+
"",
318+
"# Usage:",
319+
"insert_data('example.db', 'users', 'John Doe', 25)"
320+
],
321+
"tags": ["python", "sqlite", "database", "insert"],
322+
"author": "e3nviction"
323+
}
324+
]
325+
},
326+
{
327+
"categoryName": "Error Handling",
328+
"snippets": [
329+
{
330+
"title": "Safe Division",
331+
"description": "Performs division with error handling.",
332+
"code": [
333+
"def safe_divide(a, b):",
334+
" try:",
335+
" return a / b",
336+
" except ZeroDivisionError:",
337+
" return 'Cannot divide by zero!'",
338+
"",
339+
"# Usage:",
340+
"print(safe_divide(10, 2)) # Output: 5.0",
341+
"print(safe_divide(10, 0)) # Output: 'Cannot divide by zero!'"
342+
],
343+
"tags": ["python", "error-handling", "division", "utility"],
344+
"author": "e3nviction"
345+
}
346+
]
347+
},
348+
{
349+
"categoryName": "Datetime Utilities",
350+
"snippets": [
351+
{
352+
"title": "Get Current Date and Time",
353+
"description": "Retrieves the current date and time.",
354+
"code": [
355+
"from datetime import datetime",
356+
"",
357+
"def current_datetime():",
358+
" return datetime.now().strftime('%Y-%m-%d %H:%M:%S')",
359+
"",
360+
"# Usage:",
361+
"print(current_datetime()) # Output: Current date and time"
362+
],
363+
"tags": ["python", "datetime", "current", "utility"],
364+
"author": "e3nviction"
365+
},
366+
{
367+
"title": "Calculate Date Difference",
368+
"description": "Calculates the difference between two dates.",
369+
"code": [
370+
"from datetime import datetime",
371+
"",
372+
"def date_difference(date1, date2):",
373+
" format = '%Y-%m-%d'",
374+
" d1 = datetime.strptime(date1, format)",
375+
" d2 = datetime.strptime(date2, format)",
376+
" return abs((d2 - d1).days)",
377+
"",
378+
"# Usage:",
379+
"print(date_difference('2024-01-01', '2024-01-10')) # Output: 9"
380+
],
381+
"tags": ["python", "datetime", "difference", "utility"],
382+
"author": "e3nviction"
383+
}
384+
]
236385
}
237386
]

0 commit comments

Comments
 (0)