Skip to content

Instantly share code, notes, and snippets.

View likema's full-sized avatar

Like Ma likema

View GitHub Profile
@likema
likema / CheckStdCHeaders.cmake
Last active October 22, 2019 13:34
CMake macro to check ANSI C header files
# - Check ANSI C headers
# CHECK_STDC_HEADERS ()
#
# Once done it will define STDC_HEADERS, HAVE_STDLIB_H, HAVE_STDARG_H,
# HAVE_STRING_H and HAVE_FLOAT_H, if they exist
#
MACRO (CHECK_STDC_HEADERS)
IF (NOT CMAKE_REQUIRED_QUIET)
MESSAGE (STATUS "Checking whether system has ANSI C header files")
ENDIF (NOT CMAKE_REQUIRED_QUIET)
@likema
likema / CheckCCompiles.cmake
Last active October 22, 2019 13:35
CMake macro to check if given C source file compiles and links into an executable
# - Check if given C source file compiles and links into an executable
# CHECK_C_COMPILES(<file> <var> [FAIL_REGEX <fail-regex>])
#
# <file> - source file to try to compile, must define 'main'
# <var> - variable to store whether the source code compiled
# Will be created as an internal cache variable.
# <fail-regex> - fail if test output matches this regex
#
# The following variables may be set before calling this macro to modify
# the way the check is run:
@likema
likema / samsung-smart
Last active August 2, 2023 01:32
Samsung SATA SSD SMART info.
#!/bin/sh
get() {
echo "$SMART_INFO" | awk "/$1/ {print $2}"
}
device_number() {
printf "%u\n" 0x`stat -c $2 $1`
}
@likema
likema / acelog.vim
Created March 18, 2019 16:07
VIM syntax file for ACE log.
" Vim syntax file
" Language: ACE log file
" Maintainer: Like Ma <likemartinma@gmail.com>
" Latest Revision: 2019-03-17
if exists("b:current_syntax")
finish
endif
let s:cpo_save = &cpo
@likema
likema / glibc.cmake
Last active October 13, 2023 09:20
CMake macro to detect glibc version by filename.
# - Check glibc version
# CHECK_GLIBC_VERSION()
#
# Once done this will define
#
# GLIBC_VERSION - glibc version
#
MACRO (CHECK_GLIBC_VERSION)
EXECUTE_PROCESS (
COMMAND ${CMAKE_C_COMPILER} -print-file-name=libc.so.6
@likema
likema / gpcb
Created March 15, 2017 10:47
Push current git branch to origin
#!/bin/sh
current_branch=`git rev-parse --abbrev-ref HEAD`
if [ -z "current_branch" ]; then
echo "You are not in a git repository." >&2
exit 1
fi
git push ${1:--u} origin $current_branch
@likema
likema / gco
Last active March 15, 2017 09:14
Checkout back to the last used git branch like cd -
#!/bin/sh
current_branch=`git rev-parse --abbrev-ref HEAD`
if [ -z "$current_branch" ]; then
echo "You are not in a git repository." >&2
exit 1
fi
branch=${1:-develop}
[ "$current_branch" = "$branch" ] && exit 0
@likema
likema / gluster_docker
Last active July 19, 2022 02:05
Create and configure GlusterFS in Docker.
#!/bin/sh
GLUSTER_IMAGE=gluster/gluster-centos
gluster_ip_addr() {
local name=$1
docker inspect $1 | sed -n 's/.*"IPAddress":[[:blank:]]\+"\([^"]\+\)".*/\1/p' | sort -u
}
gluster_status() {
@likema
likema / remove_old_kernels
Last active May 5, 2020 09:12
Remove old Debian/Ubuntu kernel versions.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim: set ts=4 sw=4 sts=4 et:
from distutils.version import LooseVersion
from subprocess import Popen, PIPE
from re import compile as rcomp
from os import uname, system
from sys import exit
from argparse import ArgumentParser, ArgumentTypeError
@likema
likema / ssl_display
Last active May 1, 2016 16:43
Show SSL certificate (from file or tcp) , certificate request and private key.
#!/bin/sh
if [ $# -lt 1 ]; then
echo "$0 <host:port|SSL certificate|SSL certificate request|private key>" >&2
exit 1
fi
src=$1
if [ -f $1 ]; then
grep -q -- '-BEGIN CERTIFICATE-' $src && openssl x509 -in $src -text -noout