gist github shortcode

Gist

Embed gist codes to your website. Source idea from jekyll-gist.

option description
filename filename specific embed
lang override language syntax highlighter default based on filename extension
line embed custom lines
1
{% gist meredrica/088f5a593a2a7184202850c58bcb48d1 %}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash

# remove what's there
rm source/_posts/*.md

# download blogs
node_modules/.bin/hexo migrate blogger 'http://blog.meredrica.org/feeds/posts/default?alt=json&max-results=10000'
node_modules/.bin/hexo migrate blogger 'http://jujitsu.westreicher.org/feeds/posts/default?alt=json&max-results=10000'

# fix image links generated by migrate
# they will look like this: [![](link to small img)](link to larg img)
# this is an image that is the anchor text to the big immage
# this perl command replaces the anchor and inserts a new image tag that points to the large one
#
# regex broken down
#
# \[!\[]\(http.*?\)]
# matches the start of the anchor tag like: [![] (http:...)]
#
# (\(http.*?\))
# matches the second part (http:....) including the brackets and captures it in group 1
#
# this part of the regex produces the new image tag with the matched group 1
# ![]\1
#
perl -p -i -e 's/\[!\[]\(http.*?\)](\(http.*?\))/![]\1/g' source/_posts/*

# download the images to the local folder
node_modules/.bin/hexo migrate image

# strip all html tags and their attributes
perl -p -i -e 's/<.*?>//g' source/_posts/*

# replace all occurances of mor than 3 empty lines with just two of them
# this is required because the blogger migrate creates a lot of empty lines
# the tag replacement from above then creates even more
perl -0 -p -i -e 's/\n{3,}/\n\n/g' source/_posts/*

# remove all generated .bak files
rm source/_posts/*.bak

1
{% gist dimaslanjaka/a6aa24a8fa7a13999ee3dac077fa21fe filename:anonymize-ip.php %}
php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php

function anonIp($ip)
{
if (strpos($ip, ".") !== false) { // detect IP type by dots instead of length
$pieces = explode(".", $ip);
$nPieces = count($pieces);
$pieces[$nPieces - 1] = $pieces[$nPieces - 2] = "XXX";
return implode(".", $pieces);
} else {
$pieces = explode(":", $ip);
$nPieces = count($pieces);
$pieces[$nPieces - 1] = $pieces[$nPieces - 2] = "XXXX";
return implode(":", $pieces);
}
}

get specific lines

1
{% gist dimaslanjaka/a6aa24a8fa7a13999ee3dac077fa21fe filename:anonymize-ip.php line:1-7 %}
php
1
2
3
4
5
6
7
<?php

function anonIp($ip)
{
if (strpos($ip, ".") !== false) { // detect IP type by dots instead of length
$pieces = explode(".", $ip);
$nPieces = count($pieces);

old hexo gist

1
{% gist 996818 %}

new hexo gist

1
{% gist imathis/996818 %}
1
2
3
4
5
6
7
8
@@ -590,7 +590,7 @@ class SpritesTest < Test::Unit::TestCase
it "should generate a sprite from nested folders" do
css = render <<-SCSS
- @import "nested/*.png";
+ @import "nested/**/*.png";
@include all-nested-sprites;
SCSS
assert_correct css, <<-CSS

new hexo gist with override options

1
{% gist imathis/996818 lang:diff caption:'DIFF changes' %}
DIFF
1
2
3
4
5
6
7
8
@@ -590,7 +590,7 @@ class SpritesTest < Test::Unit::TestCase
it "should generate a sprite from nested folders" do
css = render <<-SCSS
- @import "nested/*.png";
+ @import "nested/**/*.png";
@include all-nested-sprites;
SCSS
assert_correct css, <<-CSS

new hexo gist with URL and override options

1
{% gist https://gist.github.com/smourier/f77617a802f097aea4b4f3778108b5ef lang:ts %}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// by design, this returns the same values as .NET's System.Random
export default class Random {
private static readonly INT_MAX_VALUE: number = 0x7fffffff;
private static readonly INT_MIN_VALUE: number = 0x80000000;
private static readonly MSEED = 161803398;

private inext = 0;
private inextp = 21;
private seedArray = new Array(56);

constructor(seed: number) {
var subtraction = (seed == Random.INT_MIN_VALUE) ? Random.INT_MAX_VALUE : Math.abs(seed);
let mj = Random.MSEED - subtraction;
this.seedArray[55] = mj;
let mk = 1;
for (var i = 1; i < 55; i++) {
const ii = (21 * i) % 55;
this.seedArray[ii] = mk;
mk = mj - mk;
if (mk < 0) {
mk += Random.INT_MAX_VALUE;
}

mj = this.seedArray[ii];
}

for (var k = 1; k < 5; k++) {
for (var i = 1; i < 56; i++) {
this.seedArray[i] -= this.seedArray[1 + (i + 30) % 55];
if (this.seedArray[i] < 0) {
this.seedArray[i] += Random.INT_MAX_VALUE;
}
}
}
}

protected sample = () => this.internalSample() * (1 / Random.INT_MAX_VALUE);

public nextInteger = () => this.internalSample();
public nextIntegerBetween = (minValue: number, maxValue: number) => Math.floor(this.nextNumberBetween(minValue, maxValue));
public nextIntegerLessThan = (maxValue: number) => Math.floor(this.nextNumberLessThan(maxValue));
public nextNumber = () => this.sample();
public nextNumberBetween(minValue: number, maxValue: number) {
if (minValue > maxValue)
throw new Error("Argument out of range.");

var range = maxValue - minValue;
if (range <= Random.INT_MAX_VALUE)
return this.sample() * range + minValue;

return this.getSampleForLargeRange() * range + minValue;
}

public nextNumberLessThan(maxValue: number) {
if (maxValue < 0)
throw new Error("Argument out of range.");

return this.sample() * maxValue;
}

private getSampleForLargeRange() {
var result = this.internalSample();
var negative = this.internalSample() % 2 == 0;
if (negative) {
result = -result;
}

let d = result;
d += Random.INT_MAX_VALUE - 1;
d /= 2 * Random.INT_MAX_VALUE - 1;
return d;
}

private internalSample() {
var locINext = this.inext;
var locINextp = this.inextp;

if (++locINext >= 56) {
locINext = 1;
}

if (++locINextp >= 56) {
locINextp = 1;
}

let retVal = this.seedArray[locINext] - this.seedArray[locINextp];
if (retVal == Random.INT_MAX_VALUE) {
retVal--;
}

if (retVal < 0) {
retVal += Random.INT_MAX_VALUE;
}

this.seedArray[locINext] = retVal;
this.inext = locINext;
this.inextp = locINextp;
return retVal;
}
}
avatar
Dimas Lanjaka (L3n4r0x)
All in one collection shortcodes for hexo
Follow Me
Announcement
This is my Blog
Recent Post
Info
Article :
0
UV :
PV :
Last Push :