Saturday, April 21, 2018

Macos: Hide extra partitions in Clover

List partitions :
List UUID of partitions to hide :
Hide the UUID in Clover Configurator | Gui | Hide Volume :

Sunday, April 15, 2018

Macos: Where is my Firefox profile ?

  • Suppose you want to retrieve your Firefox profile and move it because it has initially been installed on another HDD.
  • Copy your profile directory from your old HDD, e.g. :
/Volumes/osx/Users/jerome/Library/Application\ Support/Firefox/Profiles/2ii3i4a1.default/
  • Into the new disk at :
/Users/jerome/Library/Application\ Support/Firefox/Profiles/
  • Copy the name of the default profile that has been created on the new disk
  • Remove this default profile 
  • Rename the old default profile like the new one just copied.

Macos: how to tab between buttons

Wednesday, April 11, 2018

Linux: Find Out What Process Are Using Swap Space

Source : Linux: Find Out What Process Are Using Swap Space
for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less

Wednesday, March 28, 2018

Perl: sort version numbers

Before :
perl  -e 'use version; @f= map {$_->[0]} sort map {[$_, /--([^-]+)--[^-]+\./]} ("toto--1.0--1.1.sql", "toto--1.10--1.11.sql", "toto--1.1--1.2.sql"); print "@f\n"'
toto--1.0--1.1.sql toto--1.10--1.11.sql toto--1.1--1.2.sql
After :
perl  -e 'use version; @f= map {$_->[0]} sort {$a->[1] cmp $b->[1]} map {[$_, version->declare(/--([^-]+)--[^-]+\./)]} ("toto--1.0--1.1.sql", "toto--1.10--1.11.sql", "toto--1.1--1.2.sql"); print "@f\n"'
toto--1.0--1.1.sql toto--1.1--1.2.sql toto--1.10--1.11.sql

Tuesday, March 6, 2018

Clojure: print exception stack trace

(log/error (apply str (interpose "\n" (.getStackTrace e))))

Monday, February 26, 2018

Clojure: nth line of Pascal triangle

((fn [n] (last (take n (iterate #(map + `(0 ~@%) `(~@% 0)) [1])))) 4)
(1 3 3 1)

Wednesday, January 24, 2018

Clojure: simple closure

Given a positive integer n, return a function (f x) which computes x^n.
(((fn [n] (fn [x] (apply * (repeat n x)))) 2) 16)
256
or
((partial (fn [n x] (apply * (repeat n x))) 2) 16)
256

Tuesday, January 23, 2018

Clojure: intersection implementation

((comp set filter) #{0 1 2 3} #{2 3 4 5})
#{3 2}

Sunday, January 21, 2018

Clojure: map construction

((fn [kvect, vvect] (apply hash-map (interleave kvect vvect))) [:a :b :c] [1 2 3])
{:c 3, :b 2, :a 1}

Thursday, January 18, 2018

Clojure: split-at implementation

((juxt take drop) 2 [[1 2] [3 4] [5 6]])
[([1 2] [3 4]) ([5 6])]

Wednesday, January 17, 2018

Clojure: replicate elements in sequence

((fn [s n] (mapcat (fn [x] (repeat n x)) s)) [1 2 3] 2)
((1 1 2 2 3 3))

Clojure: interleave implementation

((fn interlive [s1 s2] (mapcat vector s1 s2)) [:a :b :c] [1 2 3])
(:a 1 :b 2 :c 3)

Clojure: flatten implementation

((fn flat [s] (if (sequential? s) (mapcat flat s) [s])) '((1 2) 3 [4 [5 6]]))
(1 2 3 4 5 6)

Monday, January 15, 2018

Clojure: remove consecutive duplicates from a sequence

(#(map first (partition-by identity %)) [1 1 2 3 3 2 2 3])
[1 2 3 2 3]

Clojure: factorial function

(#(reduce * (range 1 (+ 1 %))) 3)
6

Saturday, January 13, 2018

Clojure: generate Fibonacci sequence

((fn [n] (map second (take n (iterate (fn [[a b]] [b (+ a b)]) [0 1])))) 6)
(1 1 2 3 5 8)

Clojure: build map from value and keys sequence

((fn [defval vect] (reduce (fn [m k] (conj m {k defval})) {} vect)) 0 [:a :b])
{:a 0, :b 0}
or
((fn [defval vect] (zipmap vect (repeat defval))) 0 [:a :b :c])
{:a 0, :b 0, :c 0}

Clojure: inc map values

Source: Braveclojure
(reduce (fn [m [k v]] (assoc m k (inc v))) {} {:a 1 :b 2})
{:a 2, :b 3}
NB: In this example, reduce treats the argument {:a 1 :b 2} as a sequence of vectors, like ([:a 1] [:b 2])

or, with reduce-kv
(reduce-kv (fn [m k v] (assoc m k (inc v))) {} {:a 1 :b 2})
{:a 2, :b 3}