Skip to content

Instantly share code, notes, and snippets.

View juque's full-sized avatar

Juan Pablo Aqueveque juque

View GitHub Profile
function isPalindrome(str) {
str = str.replace(/[^a-z0-9]/i, '').toLowerCase();
if ( str.length === 0) {
return true;
}
let left = 0;
let right = str.length - 1;
@juque
juque / index.php
Created March 13, 2024 21:44
PHP + Turbo + Stimulus
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PHP + Turbo + Stimulus</title>
<script src="/javascript/turbo.es2017-umd.js"></script>
<script src="/javascript/stimulus.umd.js"></script>
<script src="/javascript/controllers/index_controller.js" data-turbolinks-track="reload"></script>
</head>
<body>
@juque
juque / script.rb
Created December 5, 2023 06:44
ruby version: Leetcode Longest Substring Without Repeating Characters
# Leetcode: Longest Substring Without Repeating Characters
# ---------------------------------------------------------
#
# script is an implementation of the sliding window technique to find the
# length of the longest substring without repeating characters in a given
# string.
def length_of_longest_substring(s)
# Empty hash to store the last index of each character in the string.
char_index = {}
@juque
juque / two_sum.rb
Created November 14, 2023 16:01
ruby version: leetcode two sum problem
# Ruby version leetcode problem two_sum
def two_sum(nums, target)
hash = {}
nums.each.with_index do |k, i|
return [ hash[target - k], i ] if hash.key?(target - k)
hash[k] = i
end
end
data = [2,1,5,4,9,6]
@juque
juque / users_set_new_password.php
Created September 15, 2023 19:36
Laravel: Set new password to user role
<?php
use \App\Models\User;
use Illuminate\Support\Str;
$users = User::where('role', 'user')->get();
foreach($users as $user) {
$newPassword = Str::random(12);
$user->password = bcrypt($newPassword);
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
https://www.reuse.cl/pages/cyberdays-2023
https://oportutek.cl/
https://www.segurycel.cl/
https://www.cardinale.cl/
https://pininaonline.com/
https://sitio.consorcio.cl/promociones/black?utm_source=CCS&utm_medium=referall&utm_campaign=black_friday
https://www.kross.cl/cyber
https://bit.ly/cyberCL
https://www.sdn.cl/BlackFriday
https://bit.ly/3qaJDXi
➜ nexstep-backend git:(master) ✗ bundle exec rake db:schema:load --trace
warning: parser/current is loading parser/ruby27, which recognizes2.7.5-compliant syntax, but you are running 2.7.2.
Please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
rake aborted!
NoMethodError: undefined method `reject' for #<String:0x00007ff525db2730>
/Users/juanpabloaqueveque/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/figaro-1.2.0/lib/figaro/application.rb:64:in `global_configuration'
/Users/juanpabloaqueveque/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/figaro-1.2.0/lib/figaro/application.rb:32:in `configuration'
/Users/juanpabloaqueveque/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/figaro-1.2.0/lib/figaro/application.rb:42:in `each'
/Users/juanpabloaqueveque/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/figaro-1.2.0/lib/figaro/application.rb:36:in `load'
/Users/juanpabloaqueveque/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/figaro-1.2.0/lib/figaro.rb:23:in `load'
@juque
juque / knop.rb
Created January 20, 2023 03:05
Ejemplo de scraping en ruby
# Tarea:
#
# Se tiene una página que muestra información tabulada usando DIVs
# Se quiere convertir a una tabla HTML.
#
# Solución:
#
# Para implementar esta solución nos ayudaremos de dos librerías o gemas
#
# 1. http - https://github.com/httprb/http
@juque
juque / netflix.rb
Created November 28, 2022 12:12
Documentales Netflix recomendados
# Documentales netflix recomendados
require 'http'
require 'nokogiri'
url = "https://mashable.com/article/best-documentaries-netflix"
content = HTTP.follow.get url
doc = Nokogiri::HTML content.to_s
doc.css('h2 em').each do |x|
puts x.content
end
Bootic.require([ 'Util' ], function(util){
var ajax = util.ajax,
buttonAsyncProducts = document.querySelector('.load-async-products'),
target = document.querySelector('.async-list > div');
buttonAsyncProducts.addEventListener('click', function(e){
var res = ajax('get', '/partials/custom-list-products', e.target.dataset, function(code, body){