Skip to content

Commit 5ee9e0c

Browse files
committed
add new recipe
1 parent 3a96919 commit 5ee9e0c

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

generate.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ function get_api(argv) {
2121
const re = /\[Recipe\]/;
2222
return get(`https://api.github.com${base_path}`, { query, auth }).then(function(issues) {
2323
issues.forEach(function(issue) {
24-
const { title, url } = issue;
25-
if (title.match(re)) {
24+
const { title, url, state } = issue;
25+
if (title.match(re) && state == 'open') {
2626
const filename = './recipes/' + slugify(title.replace(re, '')) + '.md';
2727
get(url, { auth }).then(function(issue) {
2828
const { body } = issue;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## Problem
2+
3+
You want to search and find the index of a string inside a bigger string.
4+
5+
## Solution
6+
7+
```scheme
8+
(define (string-find haystack needle . rest)
9+
(let ((start (if (null? rest) 0 (car rest))))
10+
(let* ((haystack-len (string-length haystack))
11+
(needle-len (string-length needle))
12+
(start 0))
13+
(let loop ((h-index start)
14+
(n-index 0))
15+
(let ((h-char (string-ref haystack h-index))
16+
(n-char (string-ref needle n-index)))
17+
(if (char=? h-char n-char)
18+
(if (= (+ n-index 1) needle-len)
19+
(+ (- h-index needle-len) 1)
20+
(loop (+ h-index 1) (+ n-index 1)))
21+
(if (= (+ h-index 1) haystack-len)
22+
#f
23+
(loop (+ h-index 1) 0))))))))
24+
```
25+
26+
### SRFI
27+
28+
The same functionality is provided by SRFI-13 function `string-contains` and `string-contains-ci`
29+
30+
Credit: [Jakub T. Jankiewicz](https://jcubic.pl/me)
31+
32+
## Usage
33+
34+
```scheme
35+
(let* ((input "This is hello world")
36+
(search "hello")
37+
(found (string-find input search)))
38+
(if found
39+
(begin
40+
(display (substring input found))
41+
(newline))))
42+
;; ==> "helo world"
43+
```

0 commit comments

Comments
 (0)