Skip to content

Instantly share code, notes, and snippets.

View BuonOmo's full-sized avatar
🥊
—(ಠ益ಠ)ノ

Ulysse Buonomo BuonOmo

🥊
—(ಠ益ಠ)ノ
View GitHub Profile
#!/bin/sh
gh_user=BuonOmo
curl -u $gh_user 'https://api.github.com/search/code?q=*.github.io' > req.json
# set boundaries, default: {min: 0, max: 9}
[ $# -gt 0 ] && min=$1 && shift || min=0
[ $# -gt 0 ] && max=$1 || max=9
@BuonOmo
BuonOmo / map-and-filter.md
Created July 30, 2017 06:06
A javascript function that chains map and filter

Javascript array.mapAndFilter() function.

What's that?

The mapAndFilter() method allow a user to use both mecanism without chaining. Which means that he can either return a value that will be mapped, or return undefined (e.g. omit return statement) in which case the current object will be filtered out of the array.

Optionnally, you can also set the filter token to be something else with undefined if you want your array to contain undefined items.

A filter exemple

@BuonOmo
BuonOmo / index.html
Last active December 6, 2017 00:01
mail template imageless
<div style="width:100%;padding:24px 0 16px 0;background-color:#f5f5f5;text-align:center">
<div style="display:inline-block;width:90%;max-width:680px;min-width:280px;text-align:left;font-family:Roboto,Arial,Helvetica,sans-serif">
<div style="display:block;padding:0 2px">
<div style="display:block;background:#fff;height:2px"></div>
</div>
<div>
<div style="padding:24px 32px 32px 32px;background:#fff;border-right:1px solid #eaeaea;border-left:1px solid #eaeaea" dir="ltr">
<div style="font-size:14px;line-height:18px;color:#444">
<p>Hi Steve,</p>
<p>
@BuonOmo
BuonOmo / 0-good-old-way.rb
Last active October 23, 2018 16:23
A headache in Ruby: Hash default values
students_by_option = {}
[["gym", "eddy"], ["theater", "john"], ["gym", "ned"]].each do |option, student|
students_by_option[option] = [] if students_by_option[option].nil?
students_by_option[option] << student
end
p students_by_option["theater"] # ["john"]
p students_by_option # { "gym" => ["eddy", "ned"], "theater" => ["john"] }
@BuonOmo
BuonOmo / no-cursor-script.zsh
Created October 23, 2018 09:22
hide cursor in shell script
show_cursor() {
tput cnorm
exit
}
hide_cursor() {
tput civis
}
trap show_cursor INT TERM
hide_cursor
@BuonOmo
BuonOmo / fold-string.rb
Last active December 6, 2018 23:25
Fold a string in ruby
# inspired by: https://stackoverflow.com/a/11934977/6320039
# proof of concept: https://regex101.com/r/RkHel3/2
def fold(str, length: 80, sep: "\\s")
return str if str.length < length
regexp = /((^[^#{sep}]{#{length - 1}})?(?(2)|^.{1,#{length - 2}}#{sep}))(.*)/
_, folded, _, rest = *str.match(regexp)
"#{folded}⤶\n#{fold("⤷" + rest, length: length, sep: sep)}"
@BuonOmo
BuonOmo / emojis.sh
Last active May 6, 2024 14:34
A list of all UTF-8 emojis in bash or zsh
# Obtained with the code written in next file
emoji_grinning_face=😀
emoji_grinning_face_with_big_eyes=😃
emoji_grinning_face_with_smiling_eyes=😄
emoji_beaming_face_with_smiling_eyes=😁
emoji_grinning_squinting_face=😆
emoji_grinning_face_with_sweat=😅
emoji_rolling_on_the_floor_laughing=🤣
emoji_face_with_tears_of_joy=😂
emoji_slightly_smiling_face=🙂
@BuonOmo
BuonOmo / so-comment-newbie.md
Last active March 19, 2019 09:11
Some good way to reroute a newbie on stack overflow

The posted question does not appear to include any attempt at all to solve the problem. StackOverflow expects you to try to solve your own problem first, as your attempts help us to better understand what you want. Please edit the question to show what you've tried, so as to illustrate a specific roadblock you're running into in a mcve. For more information, please see ask and take the tour.

@BuonOmo
BuonOmo / time_ago.sh
Last active July 7, 2023 12:42
Time ago in words within bash
#!/usr/bin/env bash
# Copyright (c) 2019 Ulysse Buonomo <buonomo.ulysse@gmail.com> (MIT license)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
@BuonOmo
BuonOmo / most-starred-repos.sh
Last active January 16, 2020 14:51
Most starred public repositories on GitHub.
# Forked from: https://gist.github.com/jdennes/7013672.
#
# I improved the request output!
curl -G https://api.github.com/search/repositories \
--data-urlencode 'q=stars:>1000' \
--data-urlencode 'sort=stars' \
--data-urlencode 'order=desc' \
-H 'Accept: application/vnd.github.preview' \
| jq --raw-output '.items | .[] | (.full_name + " (" + (.stargazers_count | tostring) + ")")' \
| cat -n