-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
566 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
title: "Dev Blog" | ||
date: 2024-02-22T09:22:54+01:00 | ||
draft: true | ||
categories: | ||
--- | ||
|
||
# Dev Blog | ||
|
||
In this section I will publish my research on development, exercises solutions, etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
--- | ||
title: "Leet Code Exercises" | ||
date: 2024-01-29T20:40:03+01:00 | ||
draft: false | ||
categories: dev | ||
--- | ||
|
||
# Leet Code Exercises | ||
|
||
Here is a list of my Leet Code solution (non exaustive). I am following https://neetcode.io/roadmap | ||
|
||
## Contains Duplicate | ||
|
||
```python | ||
class Solution: | ||
def containsDuplicate(self, nums: List[int]) -> bool: | ||
result = {} | ||
|
||
for item in nums: | ||
if item in result: | ||
return True | ||
result[item] = True | ||
|
||
return False | ||
``` | ||
## Valid Anagram | ||
|
||
```python | ||
class Solution: | ||
def isAnagram(self, s: str, t: str) -> bool: | ||
|
||
res = {} | ||
|
||
for item in s: | ||
if item in res: | ||
res[item]+=1 | ||
else: | ||
res[item]=1 | ||
|
||
for item in t: | ||
if item in res: | ||
res[item]-=1 | ||
if res[item]==0: | ||
del res[item] | ||
else: | ||
return False | ||
|
||
if len(res)>0: | ||
return False | ||
|
||
|
||
return True | ||
``` | ||
|
||
|
||
## Two Sum | ||
|
||
```python | ||
class Solution: | ||
def twoSum(self, nums: List[int], target: int) -> List[int]: | ||
|
||
for i in range(len(nums)): | ||
for j in range(i+1,len(nums)): | ||
if nums[i] + nums[j] == target: | ||
|
||
return [i,j] | ||
``` | ||
|
||
## Group Anagrams | ||
|
||
```python | ||
class Solution: | ||
|
||
def groupAnagrams(self, strs: List[str]) -> List[List[str]]: | ||
|
||
res = {} | ||
|
||
for s in strs: | ||
ss = str(sorted(s)) | ||
if ss in res: | ||
res[ss].append(s) | ||
else: | ||
res[ss] = [s] | ||
|
||
return (list(res.values())) | ||
``` | ||
|
||
## Top K Frequent Elements | ||
|
||
```python | ||
class Solution: | ||
def topKFrequent(self, nums: List[int], k: int) -> List[int]: | ||
if len(nums) == 1: | ||
return [nums[0]] | ||
|
||
occ = {} | ||
|
||
for i in range(len(nums)): | ||
if nums[i] in occ: | ||
occ[nums[i]] += 1 | ||
else: | ||
occ[nums[i]] = 1 | ||
|
||
socc = sorted(occ.items(),key=lambda x:x[1],reverse=True) | ||
|
||
|
||
v = list(dict(socc).keys()) | ||
return v[0:k] | ||
``` | ||
|
||
O(n) with buckets | ||
|
||
|
||
## Product of Array Except Self | ||
|
||
```python | ||
class Solution: | ||
def productExceptSelf(self, nums: List[int]) -> List[int]: | ||
answer = [1 for _ in range(len(nums))] | ||
|
||
pre = [1 for _ in range(len(nums))] | ||
post = [1 for _ in range(len(nums))] | ||
|
||
for i in range(1,len(nums)): | ||
pre[i] = pre[i-1] * nums[i-1] | ||
|
||
for i in range(len(nums)-2,-1,-1): | ||
post[i] = post[i+1] * nums[i+1] | ||
|
||
for i in range(len(nums)): | ||
answer[i] = pre[i] * post[i] | ||
|
||
|
||
|
||
return answer | ||
``` | ||
|
||
|
||
## Valid Sudoku | ||
|
||
```python | ||
class Solution: | ||
|
||
def isValidRow(self,board,row): | ||
|
||
occ = {} | ||
for i in range(9): | ||
if board[row][i] != ".": | ||
if board[row][i] in occ: | ||
return False | ||
else: | ||
occ[board[row][i]] = True | ||
|
||
|
||
return True | ||
|
||
def isValidColumn(self,board,column): | ||
|
||
occ = {} | ||
|
||
for i in range(9): | ||
if board[i][column] != ".": | ||
if board[i][column] in occ: | ||
return False | ||
else: | ||
occ[board[i][column]] = True | ||
|
||
return True | ||
|
||
def isValidBox(self,board,row,column): | ||
|
||
occ = {} | ||
for i in range(row,row+3): | ||
for j in range(column,column+3): | ||
if board[i][j] != ".": | ||
if board[i][j] in occ: | ||
return False | ||
else: | ||
occ[board[i][j]] = True | ||
|
||
return True | ||
|
||
def isValidSudoku(self, board: List[List[str]]) -> bool: | ||
|
||
for i in range(9): | ||
if not self.isValidRow(board,i): | ||
return False | ||
|
||
if not self.isValidColumn(board,i): | ||
return False | ||
|
||
for i in range(3): | ||
for j in range(3): | ||
if not self.isValidBox(board,i*3,j*3): | ||
return False | ||
|
||
|
||
return True | ||
|
||
``` | ||
|
||
## Min Stack | ||
|
||
```python | ||
class MinStack: | ||
|
||
def __init__(self): | ||
self.stack = [] | ||
self.min_stack = [] | ||
|
||
def push(self, val: int) -> None: | ||
self.stack.append(val) | ||
if len(self.min_stack) == 0: | ||
self.min_stack.append(val) | ||
else: | ||
if self.min_stack[-1] >= val: | ||
self.min_stack.append(val) | ||
|
||
|
||
def pop(self) -> None: | ||
v = self.stack.pop() | ||
if self.min_stack[-1] == v: | ||
self.min_stack.pop() | ||
|
||
|
||
def top(self) -> int: | ||
return self.stack[-1] | ||
|
||
|
||
def getMin(self) -> int: | ||
return self.min_stack[-1] | ||
``` | ||
|
||
<!-- { | ||
"Arrays & Hashing": [ | ||
"https://leetcode.com/problems/contains-duplicate/", | ||
"https://leetcode.com/problems/valid-anagram/", | ||
"https://leetcode.com/problems/two-sum/", | ||
"https://leetcode.com/problems/group-anagrams/" | ||
] | ||
} --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
title: "My Journey Through Developing an Android App in 2023" | ||
date: 2023-09-26T11:20:24+02:00 | ||
draft: true | ||
categories: dev | ||
--- | ||
|
||
Hei everyone! Since I am working in mobile application security, I thought it wuld be a great idea to develop something, in order to see this world on the other side. I will probably won't use a lot of (or any at all) critical functionalities, but I hope it will help you to learn something about Android development in 2023. | ||
|
||
This is not my first Android app. In 2019, I developed a weather app for my dad: [MeteOrsago](https://github.com/alright21/MeteOrsago). It is quite simple but it was interesting to me because I learnt how to handle API data (from a plain TXT file 😅) and show them on screen. I was quite proud of it, but I stopped developing it after I completed the goal of the app: show weather data from my house's weather station, and other data related to my city and region in Italy. | ||
|
||
When I started mobile security, I thought that the development was similar to it, except for the language (bye Java, welcome Kotlin), but I was unaware about Jetpack Compose and what Google developed recently. I was quite overwelmed, and I still do not know almost anything: I will probably make a lot of mistake because I haven't studied the theory a lot, but I am happy to learn from you if you have any suggestions. | ||
|
||
|
||
## The Idea | ||
|
||
Nowdays, I live alone in Milan. There are countless advantages compared to living with parents, but every aspect of life is now on my control: cleaning the house, do groceries, organize your weekly menu, to name a few. I love preparing my meals everyday, but I prefer to have all the weekly menu organized, with all the ingredient already in my fridge. It has two advantages: you save time (you do groceries once a week) and you save money (you do not tend to buy randomly or what you do not necessary need). That's why I came up with this idea: a mobile application that creates the weekly menu for you. One step back: no AI and nothing fancy (for now): I just want to store a collection of meals, and every week the app will create the menu (on Sunday) for the week days. In the app, you should be able to: | ||
|
||
0. generate a random weekly menu by clicking on a button on the home page, if the menu has not been created yet. | ||
1. see the current week menu on the home page. | ||
2. move around different activities using a side menu | ||
3. automatically archive old menu on the following Sunday. When this happens, the home page will have a single button to create the new menu | ||
4. add, modify or delete meals inside a Meals activity. You should be able to see the list of the meals, and each meal should have a property `timeOfDay` to indicate if this meal is suitable for lunch or dinner (yeah, I am a bit strange) | ||
5. see all the archived menus, in another actitity. Each menu will be identified by the current year and the week numer (1-52) | ||
|
||
Based on this info, this is what I came up with, drawn using my old iPad Air (I am not an expert on this). | ||
|
||
<figure> | ||
<img src="/assets/mobile_dev_mymenu_prototype.png" alt="MyMenu Prototype" style="width:100%"> | ||
<figcaption>Prototype of MyMenu</figcaption> | ||
</figure> | ||
|
||
## Translating Ideas to Code | ||
|
||
Thinking about an app can be quite simple, but creating it, programming it, is a bit daunting for me. Since I do not know a lot about the newest way to develop an Android app, I need some info. I also love to architect my projects in the best possible way, following guidelines and best practices: I found out that Google offers some courses directly on [developer.android.com](https://developer.android.com/). I went through their [Modern Android App Architecture](https://developer.android.com/courses/pathways/android-architecture) but I stopped because there's was a lot I didn't know anything about. It is a completely new world! | ||
|
||
I decided to move my attention to some practical execises, and I think Android Developer's course called [Jetpack Compose for Android Developers](https://developer.android.com/courses/jetpack-compose/course) is great! Jetpack Compose offers great flexibility but you have to rethink your way of developing applications, especially on what concerns UI and UI management. For example, I learnt a lot about Composables (pieces of UI used as building blocks to create your screen), layouts and how you can place these composable following Material Guidelines, the concept of state, etc. If you are not comfortable with these concepts, I highly recommend these courses: Google has put a lot of effort in them, and they are all free! | ||
|
||
|
File renamed without changes.
Oops, something went wrong.