Skip to content

Instantly share code, notes, and snippets.

View pgaspar's full-sized avatar

Pedro Gaspar pgaspar

View GitHub Profile
@pgaspar
pgaspar / README.md
Last active June 3, 2021 13:49
Super simple TCP Ruby chat 💬

Introduction

This is a super simple TCP Chat Server that you can interact with using Netcat (i.e. the nc command on your terminal).

Try it yourself!

Run the server:

$ ruby tcp.rb
@pgaspar
pgaspar / array_uniq.rb
Created October 29, 2018 02:36
Quick exploration around how Ruby's Array#uniq is implemented
# How does Ruby implement Array#uniq?
# See: https://github.com/ruby/ruby/blob/trunk/array.c#L4140-L4144
ary = [4,1,2,4,3,2,5]
hsh = {}
# Iterate over the array, adding each element to the hash
ary.each { |el| hsh[el] = el }
hsh
Verifying my Blockstack ID is secured with the address 1JTr9JrYzBPC6rirQLjcALiKxGgUqtzRJA https://explorer.blockstack.org/address/1JTr9JrYzBPC6rirQLjcALiKxGgUqtzRJA
@pgaspar
pgaspar / emoji-mapping.json
Created July 5, 2017 15:02
Emoticon code to Emoji UTF-8. 🙌
{
":smile:": "😄",
":laughing:": "😆",
":blush:": "😊",
":smiley:": "😃",
":relaxed:": "☺️",
":smirk:": "😏",
":heart_eyes:": "😍",
":kissing_heart:": "😘",
":kissing_closed_eyes:": "😚",
@pgaspar
pgaspar / screengif-bash-snippet.md
Last active February 4, 2016 15:47
Screengif bash snippet

Screengif bash snippet

Add this to your .bash_profile or whatever you use.

# Running: gif demo.mov
# Outputs: demo.gif
gif() {
  name=$(echo "$1" | cut -f 1 -d '.')
  screengif -i "$1" -o "$name.gif" --fuzz 0
}
@pgaspar
pgaspar / jk-instastream.user.js
Created February 6, 2013 15:18
J/K key navigation for Instagram's new online stream. Drop this file on your chrome://chrome/extensions/ page or use it with Greasemonkey (or similar tools). On userscripts.org: http://userscripts.org/scripts/show/158521
// ==UserScript==
// @name Instagram Stream JK Navigation
// @description Adding J/K key navigation to instagram's new online stream
// @version 1.0.0
// @author Pedro Gaspar
// @include http://www.instagram.com/*
// @include http://instagram.com/*
// ==/UserScript==
// a function that loads jQuery and calls a callback function when jQuery has finished loading
@pgaspar
pgaspar / dynamic_attributes.py
Created December 12, 2010 02:16
This class shows how to create dynamic keys that are only processed when called explicitly for the first time. If you run it as a script it will run some tests that will (hopefully) make it easy to understand.
class T(object):
"""
This class shows how to create dynamic attributes that are only processed when called directly for the first time.
After the first call, it returns the previously fetched value.
The dynamic attributes must be in the _dynamic dictionary and must have a processing method with the following name:
get_<dynamic_attribute_name>(self)
"""