View index.html
<!-- posts.json must be at root level -->
{{ $items := getJSON "posts.json" }}
{{ range $item := $items }}
<a href="{{ $item.url }}">{{ $item.name }}</a>
{{ end }}
View resize.sh
url=https://example.com/hello.jpg
out=resized.png
wget $url -O image.jpg
convert image.jpg -resize 320 $out
View logs.sh
tail -n 100 /var/log/auth.log
View commafy.py
import locale
locale.setlocale(locale.LC_ALL, 'en_US')
def commafy(n):
return locale.format('%d', n, grouping=True)
View shell.py
from subprocess import PIPE, run
def out(command):
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True, shell=True)
return result.stdout
hello = out('echo "hello"')
print(hello)
View scrape.py
import time
from selenium import webdriver
driver = webdriver.Chrome('./chromedriver')
driver.get('https://ui.lkqd.com/login')
assert 'LKQD' in driver.title
time.sleep(2)
username_field = driver.find_element_by_name('username')
username_field.send_keys('myusername')
View capitalize.js
import _ from 'lodash';
export default function capitalize(s) {
// lodash only capitalizes first word
return _.snakeCase(s).split(`_`).map(x => _.capitalize(x)).join(` `);
}
View base64.js
const fs = require('fs');
const data = fs.readFileSync('data.txt', 'binary');
const base64 = new Buffer(data, 'binary').toString('base64');
console.log(base64);
View append_csv.js
const fs = require('fs');
new Promise((resolve, reject) => {
// read filenames in current directory
fs.readdir(__dirname, function(error, filenames) {
if (error) return reject(error);
// filter out only csv files
resolve(filenames.filter(filename => /\.csv$/i.test(filename)));
});
View particles.js
const json = {
"particles": {
"number": {
"value": 25,
"density": {
"enable": true,
"value_area": 800
}
},
"color": {