Skip to content

Instantly share code, notes, and snippets.

View akosiyawin's full-sized avatar
🚀
Focusing

Darwin Marcelo akosiyawin

🚀
Focusing
  • Imelda Batol, Samal Bataan, Philippines
View GitHub Profile
@akosiyawin
akosiyawin / SearchQuery[Laravel].php
Last active June 20, 2022 01:58
One way of doing dynamic search in all columns.
<?php
private function searchConcats($query, $search)
{
$query->orWhere(DB::raw('CONCAT(registrants.student_year,"-",LPAD(registrants.student_no,4,0))'), "LIKE", "%" . $search . "%");
$query->orWhere(DB::raw('CONCAT(registrants.first_name," ",registrants.last_name)'), "LIKE", "%" . $search . "%");
$query->orWhere(DB::raw('CONCAT(registrants.last_name," ",registrants.first_name)'), "LIKE", "%" . $search . "%");
}
public function index(Request $request) {
@akosiyawin
akosiyawin / Debounce.js
Created June 20, 2022 01:50
Global function for debouncing
//Use this to your reactive data/state.
function debounce(Callback, delay = 500) {
if (typeof window.DEBOUNCER !== 'undefined') {
clearTimeout(window.DEBOUNCER);
}
window.DEBOUNCER = setTimeout(() => {
Callback();
}, 500);
@akosiyawin
akosiyawin / $profile.bash
Last active February 19, 2023 00:41
My $PROFILE For Smart Terminal
using namespace System.Management.Automation
using namespace System.Management.Automation.Language
# Alias
function get-gitstatus {
git status $args
}
function get-gitcommit {
git commit -am $args
}
@akosiyawin
akosiyawin / download.js
Created October 26, 2022 00:26
Download a file from same/different origin.
//It is important to add the origin to the AllowedOrigins on your backend. Avoid using wildcard like '*' - chances it will not work.
function forceDownload(url, fileName) {
const xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
xhr.responseType = "blob";
xhr.onload = function () {
const urlCreator = window.URL || window.webkitURL;
const imageUrl = urlCreator.createObjectURL(this.response);
const tag = document.createElement("a");
@akosiyawin
akosiyawin / PaginationApi.vue
Created November 4, 2022 00:42
Pagination for API using Vue.js
<script setup>
import Pagination from "laravel-vue-pagination";
defineProps({
data: {
type: Object,
required: true,
},
getter: {
type: Function,
required: true,
@akosiyawin
akosiyawin / AWS Public Upload.js
Created February 19, 2023 00:48
Upload file to AWS S3 with public permission.
import { S3Client } from "@aws-sdk/client-s3";
import { Upload } from "@aws-sdk/lib-storage";
const parallelUploads3 = new Upload({
client: new S3Client({
region: "ap-southeast-2",
credentials: {
accessKeyId: props.accessKeyID,
secretAccessKey: props.secretKey,
},