Skip to content

Instantly share code, notes, and snippets.

View jcberthon's full-sized avatar

Jean-Christophe jcberthon

View GitHub Profile
@jcberthon
jcberthon / string_ext.rb
Created June 12, 2012 10:49 — forked from erskingardner/string_ext.rb
Convert String to Boolean value
class String
def to_boolean
return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
return false if self == false || self.nil? || self.empty? || self =~ (/(false|f|no|n|0)$/i)
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
end
end
@jcberthon
jcberthon / report_duplicate.rb
Created June 21, 2012 13:11
Return the duplicated elements of an enumerable (e.g. array) in Ruby
# Source: http://www.dzone.com/snippets/identify-duplicates-array
module Enumerable
# Returns any duplicates entry if found
# Usage: <enumerable>.report_duplicate
def report_duplicate
inject({}) {|h,v| h[v]=h[v].to_i+1; h}.reject{|k,v| v==1}.keys
end
end
@jcberthon
jcberthon / init_end_boot_script
Created July 20, 2012 12:48
Simple init script that is launch at the end of the boot process (example) for openSUSE or Fedora (compatible with systemd)
#!/bin/sh
### BEGIN INIT INFO
# Provides: nothing
# Required-Start: $all
# Default-Start: 3 5
# Default-Stop: 4
# Short-Description: single_line_description
# Description: multiline_description
### END INIT INFO
@jcberthon
jcberthon / mount.sh
Created February 17, 2013 10:02
I have found this shell script on http://pastebin.com/DYUBe7dK looks interesting!
#!/usr/bin/env bash
# call with `mount.sh true` for debug messages
home_vols=( "/Volumes/NFS_mount" ) # if more than one mountpoint then order is important
home_router_mac="0:23:46:9d:e:f7" # use code below to identify this data
mounts=( `mount | grep /Volumes | awk {'print$3'}` )
router_ip=`netstat -rnf inet | grep default | awk {'print$2'}`
router_mac=`netstat -rnf inet | grep -v link | grep -w ^$router_ip | awk {'print$2'}`
#echo $router_mac #for current router's MAC address
@jcberthon
jcberthon / docker-img-gc
Last active September 11, 2017 02:59 — forked from anildigital/gist:862675ec1b7bccabc311
Remove dangling docker images and volumes
docker images --quiet --filter=dangling=true | xargs --no-run-if-empty docker rmi
@jcberthon
jcberthon / ssh-fingerprint
Created September 29, 2016 08:11
Print a known host public key fingerprint
# The examples below are given with the hostname github.com.
# Just change the hostname to one of your known hosts.
# These commands are particularly usefull if your ~/.ssh/known_hosts file is
# hashed!
# To display the fingerprint in its default form
ssh-keygen -l -F github.com
# To choose the algorithm for displaying the fingerprint (valid option for OpenSSH 7.2 are: `md5` or `sha256`)
ssh-keygen -l -E sha256 -F github.com
@jcberthon
jcberthon / networkmanager-wifi-powersave.md
Last active April 22, 2024 14:33
NetworkManager Wi-Fi powersaving configuration

NetworkManager WiFi Power Saving

NetworkManager supports WiFi powersaving but the function is rather undocumented.

From the source code: wifi.powersave can have the following value:

  • NM_SETTING_WIRELESS_POWERSAVE_DEFAULT (0): use the default value
  • NM_SETTING_WIRELESS_POWERSAVE_IGNORE (1): don't touch existing setting
  • NM_SETTING_WIRELESS_POWERSAVE_DISABLE (2): disable powersave
@jcberthon
jcberthon / Readme.md
Created November 8, 2016 11:21
Leap second testing

Source: https://access.redhat.com/articles/199563

This program will insert an actual leap second and may cause issues on unpatched systems. It is strongly recommended to use this in a test environment.

Build

gcc leap-a-day.c -o leap-a-day -lrt

Usage

@jcberthon
jcberthon / update-docker-compose.sh
Last active December 20, 2021 02:56
Downloading and installing/updating latest Docker Compose (command line)
#!/bin/bash
# Copyright 2017-2018 Jean-Christophe Berthon
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
$ sudo docker-containerd-ctr pprof --debug-socket /run/docker/containerd/docker-containerd-debug.sock goroutines
goroutine 1916106 [running]:
runtime/pprof.writeGoroutineStacks(0x55e3880d1be0, 0xc420200540, 0x0, 0x0)
	/usr/local/go/src/runtime/pprof/pprof.go:608 +0xa9
runtime/pprof.writeGoroutine(0x55e3880d1be0, 0xc420200540, 0x2, 0x30, 0x55e387c98c00)
	/usr/local/go/src/runtime/pprof/pprof.go:597 +0x46
runtime/pprof.(*Profile).WriteTo(0x55e3880bd6c0, 0x55e3880d1be0, 0xc420200540, 0x2, 0xc420200540, 0xc42035e9c0)
	/usr/local/go/src/runtime/pprof/pprof.go:310 +0x3ad
net/http/pprof.handler.ServeHTTP(0xc42011c6d1, 0x9, 0x55e3880dc720, 0xc420200540, 0xc42019ff00)