Skip to content

Instantly share code, notes, and snippets.

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

Ulysse Buonomo BuonOmo

🥊
—(ಠ益ಠ)ノ
View GitHub Profile
@gabrielbarros
gabrielbarros / github-keys.txt
Created March 8, 2019 23:33
Github SSH key and GPG
https://github.com/USER.keys
https://github.com/USER.gpg
require 'fiddle'
color_iter = DATA.readlines.map(&:chomp).map { |i|
i = i.to_i(16)
[(i >> 16) & 0xFF, (i >> 8) & 0xFF, i & 0xFF, 255]
}.each
SIZEOF_HEAP_PAGE_HEADER_STRUCT = Fiddle::SIZEOF_VOIDP
SIZEOF_RVALUE = 40
@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
class User < ActiveRecord::Base
...
# << REMOVE ON NEXT RELEASE
def new_column
read_attribute(:new_column) if has_attribute?(:new_column)
end
def new_column=(value)
write_attribute(:new_column, value) if has_attribute?(:new_column)
end
@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

@marcotc
marcotc / sidekiq_retry_time.csv
Created February 14, 2017 18:16
Sidekiq retry exponential backoff formula times
Retry count Retry Time Total Cumulative Time Total Cumulative Days
0 0:00:00 0:00:00 0.0
1 0:00:16 0:00:16 0.0
2 0:00:31 0:00:47 0.0
3 0:01:36 0:02:23 0.0
4 0:04:31 0:06:54 0.0
5 0:10:40 0:17:34 0.0
6 0:21:51 0:39:25 0.0
7 0:40:16 1:19:41 0.1
8 1:08:31 2:28:12 0.1
@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 <[email protected]> (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 / man-gem.zsh
Last active November 28, 2016 04:07
Create man pages with gem help
#!/bin/zsh
# Copyright (C) 2016 Ulysse Buonomo <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@v3rse
v3rse / dbservertofile.js
Created October 11, 2016 03:09
A simple json file based database server
var http = require('http');
var url = require('url');
var fs = require('fs');
var DB_FILE = 'database.json';
function init(){
//create file if it's present.
//synchronous because it needs to happen before requests can be processed
if(!fs.existsSync(DB_FILE)){
console.log(`Initialising storage.\n -Creating ${DB_FILE} file`);