Skip to content

Instantly share code, notes, and snippets.

View Cartmanishere's full-sized avatar
💻

Pranav Gajjewar Cartmanishere

💻
View GitHub Profile
@Cartmanishere
Cartmanishere / torrent-verify.py
Created September 13, 2021 01:42
A python script to verify hash of torrent downloaded files
# This code is taken from: https://stackoverflow.com/a/2573715
# Use python 2.7
# Install Bencode package: https://pypi.org/project/BitTorrent-bencode/5.0.8/#files
# Usage: python torrent-verify.py <torrent-file>
import sys
import os
import hashlib
import bencode
import StringIO
(ns clj-handlebars.http-loader
(:gen-class
:init init
:state state
:name com.github.jknack.handlebars.io.HTTPCljLoader
:implements [com.github.jknack.handlebars.io.TemplateLoader]
:constructors {[String] []}
:prefix "-")
(:import [com.github.jknack.handlebars.io URLTemplateSource]
[java.net URL]))
(ns ...
(:import [com.github.jknack.handlebars.io TemplateLoader URLTemplateSource]
[java.net URL]))
(defn http-loader-reify
[base-url]
(reify TemplateLoader
(resolve [this filename]
(str base-url filename (. this getSuffix)))
@Cartmanishere
Cartmanishere / email.js
Last active July 11, 2021 09:06
Email sending example using rendered HTML in appscript
function renderEmail(context) {
var template = HtmlService.createTemplateFromFile("emailTemplate");
template.context = context;
return template.evaluate().getContent();
}
function sendEmail(order) {
var context = {
message: "Your order has been accepted! Please find the details as follow:",
customerName: order[1],
@Cartmanishere
Cartmanishere / email.html
Last active July 11, 2021 06:00
HTML template for Automating emails in Google Sheets blog post
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<!--[if gte mso 9]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
<h1>
{{#if username}}
Welcome {{username}}!
{{else}}
Welcome user!
{{/if}}
</h1>
<body>
{{> header.hbs}}
{{content}}
</body>
public class HTTPTemplateLoader extends URLTemplateLoader {
public HTTPTemplateLoader(String baseUrl) {
setPrefix(normalize(baseUrl));
}
public String resolve(final String filename) {
return getPrefix() + filename + getSuffix();
}
;; Util to convert Clojure map to Java Hashmap
(defn clj-map->java-map
[data]
(postwalk
#(cond
(map? %) (java.util.HashMap. ^java.util.Map %)
(keyword? %) (name %)
:else %)
data))
(defn http-loader
[base-url-prefix]
(doto (proxy
[URLTemplateLoader] []
(^String resolve [^String path]
(str (proxy-super getPrefix)
path
(.getSuffix this)))