|
264 | 264 | "effect"
|
265 | 265 | ],
|
266 | 266 | "author": "dostonnabotov"
|
| 267 | + }, |
| 268 | + { |
| 269 | + "title": "MacOS Button", |
| 270 | + "description": "A macOS-like button style, with hover and shading effects.", |
| 271 | + "code": [ |
| 272 | + ".button {", |
| 273 | + " font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,;", |
| 274 | + " background: #0a85ff;", |
| 275 | + " color: #fff;", |
| 276 | + " padding: 8px 12px;", |
| 277 | + " border: none;", |
| 278 | + " margin: 4px;", |
| 279 | + " border-radius: 10px;", |
| 280 | + " cursor: pointer;", |
| 281 | + " box-shadow: inset 0 1px 1px #fff2, 0px 2px 3px -2px rgba(0, 0, 0, 0.3) !important; /*This is really performance heavy*/", |
| 282 | + " font-size: 14px;", |
| 283 | + " display: flex;", |
| 284 | + " align-items: center;", |
| 285 | + " justify-content: center;", |
| 286 | + " text-decoration: none;", |
| 287 | + " transition: all 150ms cubic-bezier(0.175, 0.885, 0.32, 1.275);", |
| 288 | + "}", |
| 289 | + ".button:hover {", |
| 290 | + " background: #0974ee;", |
| 291 | + " color: #fff", |
| 292 | + "}" |
| 293 | + ], |
| 294 | + "tags": [ |
| 295 | + "css", |
| 296 | + "button", |
| 297 | + "macos", |
| 298 | + "hover", |
| 299 | + "transition" |
| 300 | + ], |
| 301 | + "author": "e3nviction" |
267 | 302 | }
|
268 | 303 | ]
|
269 | 304 | },
|
|
1182 | 1217 | }
|
1183 | 1218 | ]
|
1184 | 1219 | },
|
| 1220 | + { |
| 1221 | + "language": "python", |
| 1222 | + "categoryName": "JSON Manipulation", |
| 1223 | + "snippets": [ |
| 1224 | + { |
| 1225 | + "title": "Read JSON File", |
| 1226 | + "description": "Reads a JSON file and parses its content.", |
| 1227 | + "code": [ |
| 1228 | + "import json", |
| 1229 | + "", |
| 1230 | + "def read_json(filepath):", |
| 1231 | + " with open(filepath, 'r') as file:", |
| 1232 | + " return json.load(file)", |
| 1233 | + "", |
| 1234 | + "# Usage:", |
| 1235 | + "data = read_json('data.json')", |
| 1236 | + "print(data)" |
| 1237 | + ], |
| 1238 | + "tags": [ |
| 1239 | + "python", |
| 1240 | + "json", |
| 1241 | + "file", |
| 1242 | + "read" |
| 1243 | + ], |
| 1244 | + "author": "e3nviction" |
| 1245 | + }, |
| 1246 | + { |
| 1247 | + "title": "Write JSON File", |
| 1248 | + "description": "Writes a dictionary to a JSON file.", |
| 1249 | + "code": [ |
| 1250 | + "import json", |
| 1251 | + "", |
| 1252 | + "def write_json(filepath, data):", |
| 1253 | + " with open(filepath, 'w') as file:", |
| 1254 | + " json.dump(data, file, indent=4)", |
| 1255 | + "", |
| 1256 | + "# Usage:", |
| 1257 | + "data = {'name': 'John', 'age': 30}", |
| 1258 | + "write_json('data.json', data)" |
| 1259 | + ], |
| 1260 | + "tags": [ |
| 1261 | + "python", |
| 1262 | + "json", |
| 1263 | + "file", |
| 1264 | + "write" |
| 1265 | + ], |
| 1266 | + "author": "e3nviction" |
| 1267 | + } |
| 1268 | + ] |
| 1269 | + }, |
| 1270 | + { |
| 1271 | + "language": "python", |
| 1272 | + "categoryName": "SQLite Database", |
| 1273 | + "snippets": [ |
| 1274 | + { |
| 1275 | + "title": "Create SQLite Database Table", |
| 1276 | + "description": "Creates a table in an SQLite database with a dynamic schema.", |
| 1277 | + "code": [ |
| 1278 | + "import sqlite3", |
| 1279 | + "", |
| 1280 | + "def create_table(db_name, table_name, schema):", |
| 1281 | + " conn = sqlite3.connect(db_name)", |
| 1282 | + " cursor = conn.cursor()", |
| 1283 | + " schema_string = ', '.join([f'{col} {dtype}' for col, dtype in schema.items()])", |
| 1284 | + " cursor.execute(f'''", |
| 1285 | + " CREATE TABLE IF NOT EXISTS {table_name} (", |
| 1286 | + " {schema_string}", |
| 1287 | + " )''')", |
| 1288 | + " conn.commit()", |
| 1289 | + " conn.close()", |
| 1290 | + "", |
| 1291 | + "# Usage:", |
| 1292 | + "db_name = 'example.db'", |
| 1293 | + "table_name = 'users'", |
| 1294 | + "schema = {", |
| 1295 | + " 'id': 'INTEGER PRIMARY KEY',", |
| 1296 | + " 'name': 'TEXT',", |
| 1297 | + " 'age': 'INTEGER',", |
| 1298 | + " 'email': 'TEXT'", |
| 1299 | + "}", |
| 1300 | + "create_table(db_name, table_name, schema)" |
| 1301 | + ], |
| 1302 | + "tags": [ |
| 1303 | + "python", |
| 1304 | + "sqlite", |
| 1305 | + "database", |
| 1306 | + "table" |
| 1307 | + ], |
| 1308 | + "author": "e3nviction" |
| 1309 | + }, |
| 1310 | + { |
| 1311 | + "title": "Insert Data into Sqlite Table", |
| 1312 | + "description": "Inserts a row into a specified SQLite table using a dictionary of fields and values.", |
| 1313 | + "code": [ |
| 1314 | + "import sqlite3", |
| 1315 | + "", |
| 1316 | + "def insert_into_table(db_path, table_name, data):", |
| 1317 | + " with sqlite3.connect(db_path) as conn:", |
| 1318 | + " columns = ', '.join(data.keys())", |
| 1319 | + " placeholders = ', '.join(['?'] * len(data))", |
| 1320 | + " sql = f\"INSERT INTO {table_name} ({columns}) VALUES ({placeholders})\"", |
| 1321 | + " conn.execute(sql, tuple(data.values()))", |
| 1322 | + " conn.commit()", |
| 1323 | + "", |
| 1324 | + "# Usage:", |
| 1325 | + "db_path = 'example.db'", |
| 1326 | + "table_name = 'users'", |
| 1327 | + "data = {", |
| 1328 | + " 'name': 'John Doe',", |
| 1329 | + |
| 1330 | + " 'age': 30", |
| 1331 | + "}", |
| 1332 | + "insert_into_table(db_path, table_name, data)" |
| 1333 | + ], |
| 1334 | + "tags": [ |
| 1335 | + "python", |
| 1336 | + "sqlite", |
| 1337 | + "database", |
| 1338 | + "utility" |
| 1339 | + ], |
| 1340 | + "author": "e3nviction" |
| 1341 | + } |
| 1342 | + ] |
| 1343 | + }, |
| 1344 | + { |
| 1345 | + "language": "python", |
| 1346 | + "categoryName": "Error Handling", |
| 1347 | + "snippets": [ |
| 1348 | + { |
| 1349 | + "title": "Safe Division", |
| 1350 | + "description": "Performs division with error handling.", |
| 1351 | + "code": [ |
| 1352 | + "def safe_divide(a, b):", |
| 1353 | + " try:", |
| 1354 | + " return a / b", |
| 1355 | + " except ZeroDivisionError:", |
| 1356 | + " return 'Cannot divide by zero!'", |
| 1357 | + "", |
| 1358 | + "# Usage:", |
| 1359 | + "print(safe_divide(10, 2)) # Output: 5.0", |
| 1360 | + "print(safe_divide(10, 0)) # Output: 'Cannot divide by zero!'" |
| 1361 | + ], |
| 1362 | + "tags": [ |
| 1363 | + "python", |
| 1364 | + "error-handling", |
| 1365 | + "division", |
| 1366 | + "utility" |
| 1367 | + ], |
| 1368 | + "author": "e3nviction" |
| 1369 | + } |
| 1370 | + ] |
| 1371 | + }, |
| 1372 | + { |
| 1373 | + "language": "python", |
| 1374 | + "categoryName": "Datetime Utilities", |
| 1375 | + "snippets": [ |
| 1376 | + { |
| 1377 | + "title": "Get Current Date and Time String", |
| 1378 | + "description": "Fetches the current date and time as a formatted string.", |
| 1379 | + "code": [ |
| 1380 | + "from datetime import datetime", |
| 1381 | + "", |
| 1382 | + "def get_current_datetime_string():", |
| 1383 | + " return datetime.now().strftime('%Y-%m-%d %H:%M:%S')", |
| 1384 | + "", |
| 1385 | + "# Usage:", |
| 1386 | + "print(get_current_datetime_string()) # Output: '2023-01-01 12:00:00'" |
| 1387 | + ], |
| 1388 | + "tags": [ |
| 1389 | + "python", |
| 1390 | + "datetime", |
| 1391 | + "utility" |
| 1392 | + ], |
| 1393 | + "author": "e3nviction" |
| 1394 | + }, |
| 1395 | + { |
| 1396 | + "title": "Calculate Date Difference in Milliseconds", |
| 1397 | + "description": "Calculates the difference between two dates in milliseconds.", |
| 1398 | + "code": [ |
| 1399 | + "from datetime import datetime", |
| 1400 | + "", |
| 1401 | + "def date_difference_in_millis(date1, date2):", |
| 1402 | + " delta = date2 - date1", |
| 1403 | + " return delta.total_seconds() * 1000", |
| 1404 | + "", |
| 1405 | + "# Usage:", |
| 1406 | + "d1 = datetime(2023, 1, 1, 12, 0, 0)", |
| 1407 | + "d2 = datetime(2023, 1, 1, 12, 1, 0)", |
| 1408 | + "print(date_difference_in_millis(d1, d2))" |
| 1409 | + ], |
| 1410 | + "tags": [ |
| 1411 | + "python", |
| 1412 | + "datetime", |
| 1413 | + "utility" |
| 1414 | + ], |
| 1415 | + "author": "e3nviction" |
| 1416 | + } |
| 1417 | + ] |
| 1418 | + }, |
1185 | 1419 | {
|
1186 | 1420 | "language": "rust",
|
1187 | 1421 | "categoryName": "String Manipulation",
|
|
0 commit comments