Skip to content

Instantly share code, notes, and snippets.

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

Ulysse Buonomo BuonOmo

🥊
—(ಠ益ಠ)ノ
View GitHub Profile
@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 / 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 / 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 / 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 / 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

#!/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 / forbes.rb
Created February 7, 2017 05:56
Get to the point with forbes top 10.
puts (1..10).map do |i|
doc = Nokogiri::HTML(open("http://www3.forbes.com/leadership/the-10-best-cities-for-jobs-in-2017/#{i}/"))
(11 - i).to_s + ": " + doc.css('.articleContentText > p > strong').text.split(' – ').pop
end.reverse
@BuonOmo
BuonOmo / seachpdf.sh
Created January 24, 2017 06:54
Search for a string from all pdf in current directory, and return file name
#!/bin/sh
# Copyright (c) 2016 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 / hello.ttl
Last active December 20, 2016 07:35
My turtle hello world. https://www.w3.org/TR/turtle/
@base <https://www.wikidata.org/wiki/>
@prefix fb: <https://facebook.com/>
@prefix gh: <https://github.com/>
# Friend Of A Friend
@prefix foaf: <http://xmlns.com/foaf/0.1/>
_:me foaf:firstname "Ulysse"^^string ; # could be integer or else
@BuonOmo
BuonOmo / container-provider.zsh
Last active January 17, 2018 12:27
A tiny script to provide a container
#!/bin/zsh
# Copyright (c) 2016 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:
#