Skip to content

Instantly share code, notes, and snippets.

View GabrielModog's full-sized avatar
🤠

Gabriel Tavares GabrielModog

🤠
View GitHub Profile
function scramble(str1, str2) {
const charCount = str1
.split("")
.reduce((a, c) => {
a[c] = (a[c] || 0) + 1
return a
}, {})
for(let char of str2) {
if(!charCount[char])
return false
@GabrielModog
GabrielModog / regexp-golf.js
Created October 4, 2024 08:57
Regexp golf eloquent javascript
verify(/[c]a[rt]/,
["my car", "bad cats"],
["camper", "high art"]);
verify(/pr?op/,
["pop culture", "mad props"],
["plop", "prrrop"]);
verify(/e?rr+?[eay]/,
["ferret", "ferry", "ferrari"],
@GabrielModog
GabrielModog / numbers-again.js
Created October 4, 2024 08:21
Numbers again challenge eloquent javascript
let number = /^([+-.]?\d+|\d+[+-.]|\d+[.]\d+|\d[.]?\d*[eE][-+]?\d+)$/
// Tests:
for (let str of ["1", "-1", "+15", "1.55", ".5", "5.",
"1.3e2", "1E-4", "1e+12"]) {
if (!number.test(str)) {
console.log(`Failed to match '${str}'`);
}
}
for (let str of ["1a", "+-1", "1.2.3", "1+1", "1e4.5",
@GabrielModog
GabrielModog / ReverseString.cs
Created September 28, 2024 23:17
backup repl rancom C# code
using System;
class Program {
static void Main(string[] args) {
string result;
string userInput = Console.ReadLine();
result = ReserveStringAnotherWay(userInput);
Console.WriteLine(result);
@GabrielModog
GabrielModog / agg-strings-query.sql
Created September 27, 2024 01:30
join city names from countries query pgsql
select
c.country_name,
string_agg(a.city, ', ') as city_list
from address a
inner join country c on a.country_id = c.country_id
group by c.country_name;
create table test_data (
code_num integer,
code_text text,
code_datetime timestamp with time zone
);
create or replace procedure generate_data_samples(
in number_of_rows integer
)
language plpgsql
@GabrielModog
GabrielModog / group-iter.js
Created September 20, 2024 18:56
1 - exercises from the eloquent javascript 3rd
class Group {
constructor(arr) {
this.data = {}
this.it = []
this.pivot = -1
for(let i of arr) {
this.data[i] = i
}
this.it = Object.values(this.data) // expensive, same data (diff structure)
}
package main
import (
"context"
"fmt"
"net/http"
"time"
)
func main() {
@GabrielModog
GabrielModog / toInt.go
Created September 2, 2024 05:52
a quick bad thinking on convert string to integer with go
func ToInt(str string) int {
// 48 it's representation of the zero in ASCII table, the digits starts in this count
// challenge: https://dev.to/zanfranceschi/desafio-low-level-toint-function-19hk
var integer int
validNumber, _ := regexp.Compile("[0-9]+")
// new string only with digits
justDigits := validNumber.FindString(str)
// length of the slices only with digits
n := len(justDigits)
@GabrielModog
GabrielModog / stringer.go
Created August 31, 2024 04:22
stringer golang
package main
import "fmt"
type IPAddr [4]byte
func (ip IPAddr) String() string {
return fmt.Sprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3])
}