Skip to content

Instantly share code, notes, and snippets.

View Toscan0's full-sized avatar

Tiago Henriques Toscan0

  • Instituto Superior Técnico
  • Lisbon
View GitHub Profile
@Toscan0
Toscan0 / Balanced-Expressions.js
Last active April 6, 2023 17:28
Check if an expression is balanced or not. Return the index. if not balanced
const checkBalancedExpr = (expr) => {
let stack = [];
for(let i = 0; i < expr.length; i++) {
let char = expr[i];
const brackets = ['(', ')', '[', ']', '{', '}']
if(!brackets.includes(char)) {
continue;
}
@Toscan0
Toscan0 / Get-Missing-Number.js
Last active April 5, 2023 12:26
Given an unsorted array of nums containing n distinct numbers in the range [0, n], one is missed. Return the only number in the range that is missing from the array. O(N^2(Logn))
// Given an unsorted array of nums containing n distinct numbers in the range [0, n], one is missed.
// Return the only number in the range that is missing from the array.
// O(N^2(Logn))
const getMissingNumber = function (arr, n) {
arr.sort(a, b) => {
if(a <= b) {
return -1;
}
else {
@Toscan0
Toscan0 / Binge-Watching.js
Last active April 5, 2023 12:24
Binge-Watching code challenge - Solution
// Max 3 hours per day
// 1.01 < movies durations < 3
const durations = [1.9, 1.04, 1.25, 2.5, 1.75];
const getMinDays = function (durations) {
var nDays = 0, startIdx = 0;
durations.sort()
for (let i = (durations.length - 1) ; i >= startIdx; i--){
if(durations[i] >= 2) {
@Toscan0
Toscan0 / V-Data-Table-Iterate-Items.js
Last active April 5, 2023 12:25
Vuetify2 v-data-table - A way to iterate every item in a table
// Items
+ '<template v-for="h in headers" v-slot:[`item.${h.value}`]="{ item }">'
// ur item slot rewrite here ex {{ item[`${h.value}`] }}
+ '</template>'
@Toscan0
Toscan0 / Get-Lock-Tables.sql
Last active January 18, 2023 14:22
Get locked tables in SQL Server
USE [yourdatabase];
GO
SELECT *
FROM sys.dm_tran_locks
WHERE 1=1
AND resource_database_id = DB_ID()
AND resource_associated_entity_id = OBJECT_ID(N'dbo.yourtablename');
@Toscan0
Toscan0 / Search-In-SP.sql
Last active April 5, 2023 12:23
Search by a word in all Stored Procedures (SQL-Server)
USE [your_database_name]
GO
SELECT DISTINCT
o.name AS Object_Name,
o.type_desc
FROM sys.sql_modules m
INNER JOIN sys.objects o
ON (m.object_id = o.object_id)
WHERE REPLACE(UPPER(m.definition), ' ','') Like '%<search_word_here>%'; -- change by word to search
@Toscan0
Toscan0 / NumberConvert.cs
Last active February 8, 2022 13:43
Converts a number from one range to another range
private float NumberConvert(float oldValue, float oldMinScale, float oldMaxScale, float newMinScale, float newMaxScal)
{
float newVal = (((oldValue - oldMinScale) * (newMaxScal - newMinScale)) / (oldMaxScale - oldMinScale)) + newMinScale;
return newVal;
}