Skip to content

Instantly share code, notes, and snippets.

View mxlje's full-sized avatar
🌩️

Max Lielje mxlje

🌩️
View GitHub Profile
@mxlje
mxlje / recursive.go
Created June 29, 2017 14:13
Golang html/template recursive rendering partial
type Thing struct {
Text string
Things []Thing
}
func RootHandler(rw http.ResponseWriter, req *http.Request) {
tmpl, err := template.New("root").Parse(`
<html>
{{ define "message" }}
<li>{{ .Text }}
@mxlje
mxlje / ssl.md
Last active January 10, 2022 02:03
SSL Certificate Commands

These commands are needed every time you want to generate a new certificate signing request to give to an authority in order for them to generate and sign a certificate for you.

https://letsencrypt.org/ solves a lot of the pain involved with SSL certs, but sometimes you still need to go the "old school" route. I constantly forget how this stuff works, so I collected the most important commands (and what they do) here for easy copy & paste.

Generate new private key

@mxlje
mxlje / heredoc.rb
Last active August 10, 2018 17:19
Ruby 2.3.0 heredocs with tilde (~)
# When using heredocs in Ruby 2.3.0, use a tilde (~) instead of a minus (-)
# to remove leading whitespace while keeping indentation in the doc itself.
module I
module AM
module INDENTED
OLD = <<-END
<head>
<title>Hello World</title>
</head>
@mxlje
mxlje / 0_dropbox-image-download.md
Last active March 23, 2018 13:31
download dropbox images from Camera Uploads folder

Dropbox Camera Upload image downloader

Disclaimer: This script is very hacky and could be optimized in almost every regard. It got the job done for me a little while ago (I was very angry at Dropbox when I wrote it), and I thought I’d share it.

You have been warned.

Setup

Dropbox Keys

@mxlje
mxlje / README.md
Last active July 4, 2017 14:31
dgraph broken recursive sorting example/bug

dgraph recursive sorting bug

This gist is an extracted test case to show how sorting by timestamps in a recursive query in dgraph does not return the expected results.

dgraph version

Dgraph version   : v0.7.7
Commit SHA-1     : e065d29
([*('A'..'Z'),*('0'..'9')]-%w(0 1 I O)).sample(9).each_slice(3).map(&:join).join('-')
@mxlje
mxlje / footnotes.rb
Last active December 31, 2015 02:28
footnotes
class Redcarpet::Render::HTML
def footnote_ref(number)
@article_id ||= [*('a'..'z'),*('0'..'9')].shuffle[0,4].join
fn_ref = "<sup id='fnref-#{@article_id}-#{number}'>"
fn_ref << "<a href='#fn-#{@article_id}-#{number}' rel='footnote'>"
fn_ref << "#{number}</a></sup>"
end
def footnote_def(content, number)
# Checks status code of multiple URLs and prints them
require "mechanize"
urls = [
'http://maxlielje.co'
]
@agent = Mechanize.new
@mxlje
mxlje / one_line_server
Last active December 20, 2015 06:39
One liner ruby webserver
# run this in the terminal
# via http://ruby5.envylabs.com/episodes/419-episode-383-july-2-2013
ruby -run -e httpd . -p 5000
@mxlje
mxlje / string.rb
Created July 12, 2013 10:02
Ruby method for cleaning URL strings for display
class String
# remove protocol, www, and trailing slash from URL string
def to_clean_url
u = self
if u.start_with?('http://www.')
u = u[11..-1]
elsif u.start_with?('https://www.')
u = u[12..-1]