Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Ekisa ivermac

  • ona
View GitHub Profile
@ivermac
ivermac / shell-utility-commands.md
Last active Nov 19, 2020
Shell utility commands
View shell-utility-commands.md

check diskspace ubuntu

sudo fdisk -l

sudo lsblk

check files and directories size in a directory in ubuntu

ll --block-size=M

du -hc <directory-path> | sort -rh | head -20

@ivermac
ivermac / ansbile_tips.yml
Created Sep 18, 2020 — forked from bmwant/ansbile_tips.yml
ansible quick tips for some modules
View ansbile_tips.yml
# Check existing
- name: Ansible check file exists.
stat:
path: /etc/filename
register: file_status
- debug:
msg: "File exists..."
when: file_status.stat.exists
- debug:
msg: "File not found"
View gpg_helper.md

List gpg keys:

gpg --list-keys --keyid-format LONG

Search key in key server:

gpg --search <email>
View cron-job-file-back-up.md

I'm a mac user and I use crontab -e to render the crone job editor. I added comments that help me remember the cron job pattern/format.

# |minute (0 - 59)
# |
# | |hour (0 - 23)
# | |
# | | |day of month (1 - 31)
# | | |
View kill-pm2-god-daemon.md

Killing pm2 god daemon

ps aux | grep -i pm2 | grep <user> | grep -v grep | awk '{print $2}' | xargs kill -9

A small alteration from the github solution given here

@ivermac
ivermac / clojure-load-and-check-namespace.md
Last active Nov 23, 2019
Load and check if a namespace exists
View clojure-load-and-check-namespace.md
(defn namespace-exists?
  "check that a namespace has been loaded"
  [str-val]
  (-> str-val
      symbol
      find-ns
      nil?
      not))
      
@ivermac
ivermac / javascript-filename-in-resources-directory.md
Last active Nov 23, 2019
Using Clojure to retrieve javascript file names in resources directory
View javascript-filename-in-resources-directory.md
(:require [clojure.java.io :as io])

(defn get-file-names [directory-object files-path]
  (let [full-directory-path (.getPath directory-object)
        get-js-file-path (fn [file]
                           (str files-path (.getName file)))]
    (->> full-directory-path
         io/file
         file-seq
@ivermac
ivermac / resolve-and-call-symbol-derived-from-a-string.md
Created Sep 19, 2019
Resolve and Call symbol derived from a string
View resolve-and-call-symbol-derived-from-a-string.md
clj.user.main=> ((-> "clojure.string/blank?" symbol resolve) "")
true
clj.user.main=> ((-> "clojure.string/blank?" symbol resolve) "ivermac")
false

I used Clojure 1.8.0. The example above has been influenced by resolve clojure function

@ivermac
ivermac / 00_destructuring.md
Created Jun 28, 2019 — forked from john2x/00_destructuring.md
Clojure Destructuring Tutorial and Cheat Sheet
View 00_destructuring.md

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors and Sequences

@ivermac
ivermac / java-vararg-in-clojure.md
Last active Sep 19, 2019
Calling Java vararg function in Clojure
View java-vararg-in-clojure.md

A colleague and I were using Jedis and wanted to delete multiple keys at once without using a loop. The version of Jedis we were using has 2 del functions and the one we wanted use is a java vararg function and can be found here. We understood a Java vararg function as a variadic function in Clojure which simply means a function with infinite arity. Assuming b1 and a1 are keys in redis, the following is what we attempted initially:

(.del jedis "a1" "b1")

The above failed with the following error: IllegalArgumentException No matching method found: del for class redis.clients.jedis.Jedis clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:80)

You can’t perform that action at this time.