This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(cl-defun range (end &optional (start 0) (step 1) reverse) | |
"Returns a list of numbers from START to END incremented by STEP" | |
(let ((i start) (res (list start))) | |
(while (< i end) | |
(setq i (+ i step)) | |
(if reverse | |
(setq res (cons i res)) | |
(setcdr (last res) (cons i nil)))) | |
res)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro for (loopvar in listvar &rest body) | |
"Execute a simple for loop: (for x in '(1 2 5) (print x))." | |
;; syntax checking | |
(if (symbolp loopvar) t | |
(error (format "Syntax error 'for %s<- ...': LOOPVAR has to be a symbol" loopvar))) | |
(if (equal (symbol-name in) "in") t | |
(error (format "Syntax error 'for %s %s<- ...'" loopvar (symbol-name in)))) | |
;; unintered symbols for local variables |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; definitions | |
(defun simple-handler (f args) | |
(if (and (functionp f) (listp args)) | |
(apply f args))) | |
(defun apply-handler (X) | |
(if (and (symbolp X) (fboundp X) (boundp X)) | |
(apply (symbol-function X) (symbol-value X)))) | |
(defun apply-cons-handler (X) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# kubectl get pods -A -o json | jq -f k8s-pods-csv.jq -r > k8s-pods.csv | |
def sumarrays($arrays): | |
reduce $arrays[] as $item ( | |
[]; . as $sum | |
| [range($item | length)] | |
| map($sum[.] + $item[.]) | |
) | |
; | |
# unit conversions | |
def cpu2num($val): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEGIN { | |
ok=0; ch=0; ur=0; fl=0; sk=0; rs=0; ig=0 | |
} | |
{ | |
print $0 | |
gsub("[a-z]+=", "") | |
ok+=$3; ch+=$4; ur+=$5; fl+=$6; sk+=$7; rs+=$8; ig+=$9 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; auto-rsync-mode -- minor mode for auto rsync | |
;; | |
;; Author: @l3msh0 | |
;; | |
;;; Example | |
;; | |
;; (require 'auto-rsync) | |
;; (auto-rsync-mode t) | |
;; (setq auto-rsync-dir-alist |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pattern = ( | |
r"^(env\['(?P<model>\w+(\.\w+)*?)'\])" | |
r"((\.with_(?P<userco>((user)|(company))\(\d+\)))|" | |
r"(\.with_context\(" | |
r"(?P<context>((\{(('\w+': ?'?\w+'?)(, ?'\w+': ?'?\w+'?)*)?\})|" # context provided | |
r"(\w+='?\w+'?))(, ?\w+='?\w+'?)*)\)))*" # context overrides | |
r"(?P<browse>(\.browse\((?P<ids>\d(, ?\d+)*)\))|" | |
r"(?P<search>\.search\(\[(?P<domain>" # search begin | |
r"(('[!&|]')|" # search domain logical | |
r"(\('\w+', ?" # search domain field |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
shopt -s extglob | |
PATTERN="my-app.log" | |
MAX=10 | |
# move and recreate | |
DATE=$(date +"%Y-%m-%d") | |
LOGFILE=`ls ${PATTERN}` | |
LOGFILE_NEW="${LOGFILE}.${DATE}" |