{"id":16423347,"url":"https://github.com/ngekoding/cheat-sheet","last_synced_at":"2026-03-18T19:34:38.717Z","repository":{"id":50438909,"uuid":"55120258","full_name":"ngekoding/cheat-sheet","owner":"ngekoding","description":"Kumpulan tutorial yang saya gunakan.","archived":false,"fork":false,"pushed_at":"2024-03-15T02:24:51.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-25T01:41:15.418Z","etag":null,"topics":["cheatsheet","tips-tricks"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ngekoding.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-31T04:28:06.000Z","updated_at":"2022-07-29T05:52:34.000Z","dependencies_parsed_at":"2024-11-10T12:15:26.779Z","dependency_job_id":null,"html_url":"https://github.com/ngekoding/cheat-sheet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ngekoding/cheat-sheet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngekoding%2Fcheat-sheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngekoding%2Fcheat-sheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngekoding%2Fcheat-sheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngekoding%2Fcheat-sheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ngekoding","download_url":"https://codeload.github.com/ngekoding/cheat-sheet/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngekoding%2Fcheat-sheet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29978438,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T16:35:47.903Z","status":"ssl_error","status_checked_at":"2026-03-01T16:35:44.899Z","response_time":124,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cheatsheet","tips-tricks"],"created_at":"2024-10-11T07:39:33.042Z","updated_at":"2026-03-01T18:30:57.116Z","avatar_url":"https://github.com/ngekoding.png","language":null,"readme":"# cheat-sheet\n## GIT (Version Control)\n##### Baru bikin\n```\n- echo \"# sistem-upload\" \u003e\u003e README.md\n- git init\n- git add README.md\n- git commit -m \"first commit\"\n- git remote add origin https://github.com/ngekoding/sistem-upload.git\n- git push -u origin master\n```\n##### Mengatur Username \u0026 Email\n```\n- git config --global user.name \"Nur Muhammad\"\n- git config --global user.email \"blog.nurmuhammad@gmail.com\"\n* Cara diatas untuk mengatur disemua repositori, untuk spesifik hilangkan \"--global\"\n```\n##### PUSH\n```\n- git add .\n- git commit -m \"Your messages\"\n- git push -u origin master --\u003e master is your \"branch\"\n```\n##### PULL\n```\n- git pull origin master\n```\n##### REMOVE\n```\ngit rm file --\u003e file is your file name\n            --\u003e and then, use PUSH\n```\n##### SHOW CONFIG\n```\ngit config --list\n```\n##### REMOVE A COMMIT THAT ALREADY PUSHED\n1. `git log` to find out the commit you want to revert\n2. `git push origin +7f6d03:master` while `7f6d03` is the commit before the wrongly pushed commit. + was for force push\n\n##### Merging without Auto-Merge\n1. `git merge --no-commit --no-ff \u003clocal-branch\u003e`\n2. `git reset HEAD`\n3. To see all diff: `git diff`\n\n## PHP (How to do something?)\n##### Remove HTML Tag from string\n```\n$content = strip_tags($content);\n```\n##### Get first image from string\n```\npreg_match('/\u003cimg.+src=[\\'\"](?P\u003csrc\u003e.+?)[\\'\"].*\u003e/i', $content, $image);\necho $image['src'];\n```\n##### Remove img tag from string\n```\npreg_replace(\"/\u003cimg[^\u003e]+\\\u003e/i\", \"(image) \", $content);\necho $content;\n```\n##### Checking valid URL\n```\npublic function valid_url($url) {\n    if (!preg_match( '/^(http|https):\\\\/\\\\/[a-z0-9_]+([\\\\-\\\\.]{1}[a-z_0-9]+)*\\\\.[_a-z]{2,5}'.'((:[0-9]{1,5})?\\\\/.*)?$/i', $url)) {\n        return FALSE;\n    }\n    return TRUE;\n}\n```\n\n### PHPSpreadsheet\n\n#### Without Template\n\n```php\n// For simple access\nuse PhpOffice\\PhpSpreadsheet\\IOFactory;\nuse PhpOffice\\PhpSpreadsheet\\Style\\Border;\nuse PhpOffice\\PhpSpreadsheet\\Spreadsheet;\nuse PhpOffice\\PhpSpreadsheet\\Worksheet\\Worksheet;\nuse PhpOffice\\PhpSpreadsheet\\Writer\\Xlsx;\nuse PhpOffice\\PhpSpreadsheet\\Style\\Alignment;\nuse PhpOffice\\PhpSpreadsheet\\Style\\Fill;\n\n$spreadsheet = new Spreadsheet();\n$sheet = $spreadsheet-\u003egetActiveSheet();\n\n// Write to cell\n$sheet-\u003esetCellValue('A1', 'The Title');\n\n// Merging\n$sheet-\u003emergeCells('A3:A4');\n\n// Styling font (bold, sizing)\n$sheet-\u003egetStyle('A1')\n    -\u003egetFont()\n    -\u003esetBold(TRUE)\n    -\u003esetSize(16);\n\n// Setting column width\n$sheet-\u003egetColumnDimension('A')-\u003esetWidth(5, 'px');\n\n// Styling cell with array\n$sheet-\u003egetStyle('A3:D4')\n    -\u003eapplyFromArray([\n        'font' =\u003e ['bold' =\u003e TRUE],\n        'fill' =\u003e [\n            'fillType' =\u003e Fill::FILL_SOLID,\n            'color' =\u003e ['rgb' =\u003e 'EFEFEF'] \n        ],\n        'alignment' =\u003e [\n            'horizontal' =\u003e Alignment::HORIZONTAL_CENTER,\n            'vertical' =\u003e Alignment::VERTICAL_CENTER,\n        ]\n    ]);\n\n// Background color\n$sheet-\u003egetStyle('A'.$row)\n    -\u003egetFill()\n    -\u003esetFillType(Fill::FILL_SOLID)\n    -\u003egetStartColor()\n    -\u003esetARGB('EFEFEF');\n\n// Alignment\n$sheet-\u003egetStyle('A'.$row)\n    -\u003egetAlignment()\n    -\u003esetHorizontal(Alignment::HORIZONTAL_CENTER);\n\n// Bordering\n$sheet-\u003egetStyle('A3:D4')\n    -\u003egetBorders()\n    -\u003egetAllBorders()\n    -\u003esetBorderStyle(Border::BORDER_THIN);\n\n// Format currency\n$sheet-\u003egetStyle('A3:A10')\n    -\u003egetNumberFormat()\n    -\u003esetFormatCode('#,##0.00');\n\n// Format date\n$date = \\PhpOffice\\PhpSpreadsheet\\Shared\\Date::PHPToExcel('2024-01-01'); // Requires to apply date format\n$sheet-\u003esetCellValue('B1', $date);\n$sheet-\u003egetStyle('B1')\n    -\u003egetNumberFormat()\n    -\u003esetFormatCode('dd/mm/yyyy');\n\n$filename = 'Filename - '.time().'.xlsx';\n\nheader('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');\nheader('Content-Disposition: attachment;filename=\"'.$filename.'\"');\nheader('Cache-Control: max-age=0');\n\n$writer = new Xlsx($spreadsheet);\n$writer-\u003esave('php://output');\n```\n\n#### Using Template\n\n```php\n$reader = IOFactory::createReader('Xlsx');\n\n// Enable reading of raw cell values only, ignoring formatting (e.g., currency symbols, styles).\n// Recommended when importing uploaded files to get unformatted data.\n$reader-\u003esetReadDataOnly(true);\n\n$spreadsheet = $reader-\u003eload('/path/totemplate.xlsx');\n$spreadsheet-\u003egetProperties()\n    -\u003esetCreator('Document Creator')\n    -\u003esetTitle('Document Title');\n\n$sheet = $spreadsheet-\u003egetActiveSheet();\n\n// Add filename \u0026 header like before\n\n$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');\n$writer-\u003esave('php://output');\n```\n\n## Helper\n\n#### Checking date range availability\n\n```php\nfunction isDateRangeAvailable($conn, $dateStart, $dateEnd) {\n    $sql = \"SELECT * FROM bookings WHERE \n            (dateStart \u003e= '$dateStart' AND dateEnd \u003c= '$dateEnd') OR \n            (dateEnd \u003e= '$dateStart' AND dateStart \u003c= '$dateEnd')\";\n\n    $result = $conn-\u003equery($sql);\n\n    if ($result-\u003enum_rows \u003e 0) {\n        // There are existing bookings that overlap with the specified date range\n        return false;\n    } else {\n        // Date range is available\n        return true;\n    }\n}\n```\n\n## CSS Tricks\n#### CSS Triangle\n```\n.arrow-up {\n  width: 0; \n  height: 0; \n  border-left: 5px solid transparent;\n  border-right: 5px solid transparent;\n  border-bottom: 5px solid black;\n}\n\n.arrow-down {\n  width: 0; \n  height: 0; \n  border-left: 20px solid transparent;\n  border-right: 20px solid transparent;\n  border-top: 20px solid #f00;\n}\n\n.arrow-right {\n  width: 0; \n  height: 0; \n  border-top: 60px solid transparent;\n  border-bottom: 60px solid transparent;\n  border-left: 60px solid green;\n}\n\n.arrow-left {\n  width: 0; \n  height: 0; \n  border-top: 10px solid transparent;\n  border-bottom: 10px solid transparent; \n  border-right:10px solid blue; \n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngekoding%2Fcheat-sheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fngekoding%2Fcheat-sheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngekoding%2Fcheat-sheet/lists"}