Skip to content

Instantly share code, notes, and snippets.

View mmonette's full-sized avatar

Mike Monette mmonette

  • Reston, VA
  • 12:58 (UTC -04:00)
View GitHub Profile
@mmonette
mmonette / sysv.init.script.to.systemd.unit.file.md
Created September 25, 2018 19:27 — forked from houtianze/sysv.init.script.to.systemd.unit.file.md
Convert SysV Init scripts to Systemd Unit File

Let's say you have a SysV Init Script named foo

  1. Copy the file to /etc/init.d/foo

  2. Enable the SysV service: chkconfig --add foo

  3. Enable the SysV service: chkconfig foo on

  4. Start the service: service foo start. After this, systemd-sysv-generator will generate this file /run/systemd/generator.late/foo.service, copy this file to /etc/systemd/system by running: cp /run/systemd/generator.late/foo.service /etc/systemd/system/foo.service

  5. Edit /etc/systemd/system/foo.service by running systemctl edit foo.service, add in the following line to foo.servie (this makes the service installable)

[Install]

@mmonette
mmonette / SICPEx1.12.scm
Created March 12, 2011 23:25
SICP Exercise 1.12
;; Exercise 1.12
;; Write a procedure that computes elements of Pascal's triangle by means of a recursive process
;; 1
;; 1 1
;; 1 2 1
;; 1 3 3 1
;; 1 4 6 4 1
(define (pascal row entry)
(cond ((= row entry) 1)
@mmonette
mmonette / SICPEx1.11.scm
Created March 12, 2011 23:23
SICP Exercise 1.11
;; Exercise 1.11
;; A function is defined by the rule that f(n) = n if n < 3 and
;; f(n) = f(n-1) + 2f(n-2) + 3f(n-3) if n>= 3. Write a procedure
;; that computes f by means of a recursive process.
(define (f n)
(if (< n 3)
n
(+ (f (- n 1))
(* 2 (f (- n 2)))
@mmonette
mmonette / SICPEx1.10.scm
Created March 6, 2011 02:21
SICP Exercise 1.10
;; Exercise 1.10
;; The following procedure computes a mathematical function called Ackermann's function.
(define (A x y)
(cond ((= y 0) 0)
((= x 0) (* 2 y))
((= y 1) 2)
(else (A (- x 1)
(A x (- y 1))))))
;; What are the values of the following expressions?
@mmonette
mmonette / SICPEx1.9.scm
Created March 6, 2011 02:20
SICP Exercise 1.9
;; exercise 1.9
;; Using the substitution model, illustrate the process generated by each procedure in evaluating (+ 4 5).
;; Are these procedures iterative or recursive?
;; First version:
(define (+ a b)
(if (= a 0)
b
(inc (+ (dec a) b))))
;; evaluate (+ 4 5)
;; (inc (+ 3 5))
@mmonette
mmonette / SICPEx1.8.scm
Created March 6, 2011 02:19
SICP Exercise 1.8
;; Exercise 1.8
;; Implement a cube-root function using Newton's method for cube roots,
;; which uses the approximation function:
;; (x/(y^2) + 2y) / 3
(define (square x)
(* x x))
(define (cube x)
(* (square x) x))
@mmonette
mmonette / SICPEx1.7.scm
Created March 6, 2011 02:19
SICP Exercise 1.7
;; Exercise 1.7
;; Implement a new good-enough? function which measures how much the guess changes
;; from one iteration to the next and stops when the change is small enough.
(define (square x)
(* x x))
(define (average x y)
(/ (+ x y) 2))
(define (improve guess x)
@mmonette
mmonette / SICPEx1.6.scm
Created March 6, 2011 02:18
SICP Exercise 1.6
;; Exercise 1.6
(define (square x)
(* x x))
(define (average x y)
(/ (+ x y) 2))
(define (improve guess x)
(average guess (/ x guess)))
@mmonette
mmonette / SICPEx1.5.scm
Created March 6, 2011 02:17
SICP Exercise 1.5
;; Exercise 1.5
;; Given two definitions:
(define (p) (p))
(define (test x y)
(if (= x 0)
0
y))
;; What behavior results when the following expression is evaluated with an
;; interpreter that uses applicative-order evalaution?
(test 0 (p))
@mmonette
mmonette / SICP1.4.scm
Created March 6, 2011 02:13
Answers for SICP Ex. 1.4
;; Exercise 1.4
;; Observe that our model of evaluation allows for combinations whose operators are compound expressions.
;; Use this observation to describe the behavior of the following procedure:
(define (a-plus-abs-b a b)
((if (> b 0) + - ) a b))
;; The operator in the expression (the first item in the expression) is, in this case,
;; the result of the evaluation of the expression (if (> b 0) + -). So, the operator
;; + is returned when b>0, and - otherwise.