Skip to content

Instantly share code, notes, and snippets.

View alonsogarciapablo's full-sized avatar

Pablo Alonso alonsogarciapablo

View GitHub Profile
@alonsogarciapablo
alonsogarciapablo / design-challenge-003-0-before.js
Last active June 29, 2024 16:03
Design Challenge 003: Generating Context Menu from Legacy API Response
// Your challenge is to find ways to simplify this code further.
// You can use any patterns or refactoring techniques you find useful.
// Think about improving readability and maintainability while ensuring the
// functionality remains intact.
// Backend response
{
"operations": [
{
@alonsogarciapablo
alonsogarciapablo / 0-before.js
Last active June 25, 2024 07:48
Encapsulating collections in JavaScript 🎁
class Team {
constructor(members) {
this._members = members;
}
get members() {
return this._members;
}
set members(members) {
@alonsogarciapablo
alonsogarciapablo / design-challenge-002-0-before.js
Last active June 7, 2024 11:25
Design Challenge 002: Simplifying State Management in React
// Design Challenge 002: Simplifying State Management in React
// https://juntao.substack.com/p/design-challenge-002-simplifying
const ApprovalPanel = ({id}) => {
const [isDone, setDone] = useState(false);
const handleApprove = () => {
fetch('POST', `/rest/approval/${id}/approve`)
.then(r => r.json())
.then(data => setDone(data.isDone));
@alonsogarciapablo
alonsogarciapablo / nav-smooth-scrolling.js
Last active May 17, 2024 13:40
Smooth Scrolling for TheSignal Team's website ✨
const nav = document.querySelector('#header nav');
nav.addEventListener('click', event => {
const link = event.target;
const sectionId = link.href.split('#')[1];
const section = document.querySelector(`section#${id}`)
if (section) {
event.preventDefault();
section.scrollIntoView({ behavior: 'smooth' });
}
@alonsogarciapablo
alonsogarciapablo / refactor01.js
Last active May 17, 2024 07:34
Design Challenge 001: Building a Flexible…
const TemplateSelector = ({ templates }) => {
return (
<div>
<SearchBar />
<Category />
<TemplateList templates={templates} />
</div>
);
};
@alonsogarciapablo
alonsogarciapablo / 1-pojos.rb
Last active August 29, 2015 14:16
The Oscars 2015 - OOP in Ruby
class Genre
MALE = 'man'
FEMALE = 'woman'
def self.count
2
end
end
class Actor
@alonsogarciapablo
alonsogarciapablo / output.txt
Last active August 29, 2015 14:15
A rake task to extract valuable SEO information from a set of URLs
http://www.google.com
---------------------
TITLE: Google
LANG: es
DESCRIPTION: Google.es permite acceder a la información mundial en castellano, catalán, gallego, euskara e inglés.
KEYWORDS:
@alonsogarciapablo
alonsogarciapablo / burrito_model_awards.rb
Last active August 1, 2016 09:53
Burrito Model Awards
#!/usr/bin/env ruby
# encoding: utf-8
require 'io/console'
require 'debugger'
require 'pygments'
def winsize
$stdout.winsize
end
@alonsogarciapablo
alonsogarciapablo / .htaccess
Created August 15, 2012 11:34
Rewrite '/' to '~/public_html/web'
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ web/ [L]
RewriteRule (.*) web/$1 [L]
</IfModule>
@alonsogarciapablo
alonsogarciapablo / gist:3235818
Created August 2, 2012 09:29 — forked from denis/gist:48774
Adding git bash completion in MAC OS X
cd /tmp
git clone git://git.kernel.org/pub/scm/git/git.git
cd git
git checkout v`git --version | awk '{print $3}'`
cp contrib/completion/git-completion.bash ~/.git-completion.bash
cd ~
rm -rf /tmp/git
echo -e "source ~/.git-completion.bash" >> .profile