Skip to content

Instantly share code, notes, and snippets.

View fipar's full-sized avatar

Fernando Ipar fipar

View GitHub Profile
@fipar
fipar / profiler-hydra.el
Last active September 11, 2023 18:35
profiler-hydra.el
(global-set-key (kbd "s-p") 'hydra-profiler/body)
(defhydra hydra-profiler (:hint none :exit t)
"
Hydra Profiler (_q_uit)
_s_ start profiler
_x_ reset profiler
_k_ stop profiler
_r_ profiler report
"
("q" nil)
@fipar
fipar / copilot.el
Last active September 11, 2023 18:35
copilot.el
(execute-on-machine work-machine (add-to-list 'load-path
"~/l360/src/extern/copilot.el"))
(execute-on-machine work-machine (progn
(require 'copilot)
(define-key copilot-completion-map (kbd "y") 'copilot-accept-completion)
(define-key copilot-completion-map (kbd "n") 'copilot-next-completion)
(define-key copilot-completion-map (kbd "c") 'copilot-clear-overlay)
(global-set-key (kbd "s-u") 'copilot-complete)
))
@fipar
fipar / execute-on-machine.el
Created September 11, 2023 18:03
selectively execute elisp code depending on which machine I'm on
;; allow customizations per machine
(setq hostname (car (split-string system-name "\\.")))
(defmacro execute-on-machine (machine-name &rest body)
"Execute BODY only if the machine name matches MACHINE-NAME."
`(let ((current-machine hostname))
(when (string-equal current-machine ,machine-name)
,@body)))
(setq work-machine "mellotron")
@fipar
fipar / find_orphans.js
Created June 10, 2015 16:19
Find orphaned documents in mongodb (for pre 2.6 where cleanupOrphaned does not exist).
var database = "sample";
var collection = "tests";
var connections = [];
config = db.getMongo().getDB("config");
config.shards.find().forEach(
function (shard,_a,_i) {
connections.push(new Mongo(shard["host"]));
}
@fipar
fipar / mongodb.json
Last active November 10, 2020 05:44
Basic Grafana dashboard for MongoDB metrics (data source: https://github.com/dcu/mongodb_exporter)
{
"id": 1,
"title": "MongoDB",
"originalTitle": "MongoDB",
"tags": [],
"style": "dark",
"timezone": "browser",
"editable": true,
"hideControls": false,
"sharedCrosshair": false,
@fipar
fipar / get_hyper_shortcuts.sh
Created April 29, 2020 15:23
Generate a pdf documenting my hyper and F keys emacs shortcuts
#!/bin/bash
target=hyper-shortcuts.tex
cat <<EOF>$target
\documentclass{article}
\pagestyle{empty}
\usepackage{longtable} % Because our table will spawn more than one page
\usepackage[dvipsnames]{xcolor} % To use commands like \textcolor{red}{]}
\title{Emacs Hyper and F key shortcuts}
\begin{document}
\maketitle
@fipar
fipar / general_log.sql
Created July 15, 2015 17:07
export mysql.general_log into a text file with general log format
select 'Tcp port: 3306 Unix socket: /tmp/mysql.sock\nTime Id Command Argument'
union
select concat(date_format(event_time, '%y%m%d %H:%i:%S'), ' ', thread_id, ' ', command_type, '\t', argument)
from general_log
into outfile '/tmp/test'
fields terminated by ''
@fipar
fipar / panic-recover.go
Created November 28, 2012 21:45
Basic example of panic / recover use in golang
package main
import (
"fmt"
"time"
)
func mainLoop() {
fmt.Println("starting main loop, this will die after dividing by 0")
i := 0
@fipar
fipar / cassandra-detail_rev2.json
Created November 4, 2018 14:46
cassandra-detail with deprecated count_scalar replaced by count(scalar(
{
"__inputs": [
{
"name": "DS_PROMETHEUS",
"label": "Prometheus",
"description": "with node exporter and jmx exporter",
"type": "datasource",
"pluginId": "prometheus",
"pluginName": "Prometheus"
}
@fipar
fipar / procs_using_swap.sh
Last active May 25, 2018 23:10
Get list of process names using swap in descending order (by swap usage). Assumes swap usage is printed in kb always, which I need to validate.
grep -r VmSwap /proc/[0-9][0-9]*/status 2>/dev/null|sort -k2 -nr | \
while read procentry meminkb; do
pid=$(echo $procentry|awk -F'/' '{print $3}')
echo "$(cat /proc/$pid/comm) ($pid): $meminkb"
done 2>/dev/null |more