Skip to content

Instantly share code, notes, and snippets.

View ksamirdev's full-sized avatar
🥄
I do spoon feeds

Samir ksamirdev

🥄
I do spoon feeds
View GitHub Profile
@ksamirdev
ksamirdev / firebase-blob-uplaod.svelte
Created June 16, 2023 17:00
A simple code to upload blob on firebase storage.
<script lang="ts">
import firebaseApp from '$lib/firebase';
import { uploadBytes, getStorage, ref } from 'firebase/storage';
const onChange = (event: Event) => {
const target = event.target as HTMLInputElement;
if (!target) return;
if (target.files && target.files.length > 0) {
const selectedFile = target.files[0];
@ksamirdev
ksamirdev / s3.ts
Last active January 10, 2024 12:55
List all objects from s3 in nodejs with typescript
import { ListObjectsV2Command, type _Object } from "@aws-sdk/client-s3";
let size = 0;
let keys: _Object[] = [];
const BUCKET_NAME = "":
const OBJECTS_PREFIX = "";
async function fetchObjects(StartAfter?: string) {
const listCmd = new ListObjectsV2Command({ Bucket: BUCKET_NAME, Prefix: OBJECTS_PREFIX, StartAfter });
func containsDuplicate(nums []int) bool {
m := make(map[int]bool, len(nums))
for _, num := range nums {
if _, ok := m[num]; ok {
return true
} else {
m[num] = true
}
}
func isAnagram(s string, t string) bool {
char := make([]int, 26)
for _, v := range s {
i := int(v - 'a')
char[i]++
}
for _, v := range t {
i := int(v - 'a')
func twoSum(nums []int, target int) []int {
m := make(map[int]int, len(nums))
for i, x := range nums {
y := target - x
if v, ok := m[y]; ok {
return []int{v, i}
}
function revWithReduce(str: string): string {
return str.split("").reduce((acc, curr) => curr + acc, "");
}
function revWithLoop(str: string): string {
let reversed = "";
for (let i = str.length - 1; i >= 0; i--) {
reversed += str.at(i);
}
public class LCS {
public static int lcs(String X, String Y, int m, int n) {
// Base case: If either string is empty, LCS is 0
if (m == 0 || n == 0) return 0;
// If last characters match, include in LCS and recurse
if (X.charAt(m-1) == Y.charAt(n-1))
return 1 + lcs(X, Y, m-1, n-1);
// If they don't match, take max of excluding last char from X or Y
else
return Math.max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n));
# Thanks to Greg Hogg for an amazing explaination
# Video: https://www.youtube.com/watch?v=yKZFurr4GQA
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
l_mult = 1
r_mult = 1
n = len(nums)
l_arr = [0] * n
r_arr = [0] * n
class Solution:
def isValidSudoku(self, board: List[List[str]]) -> bool:
rows = collections.defaultdict(set)
cols = collections.defaultdict(set)
boxes = collections.defaultdict(set)
for r in range(9):
for c in range(9):
if board[r][c] == '.':
continue
from collections import defaultdict
class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
anagrams = defaultdict(list)
for st in strs:
count = [0] * 26
for c in st:
count[ord(c) - ord('a')] += 1