This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
const String _gpioExport = '/sys/class/gpio/export'; | |
const String _gpioUnexport = '/sys/class/gpio/unexport'; | |
const String _gpioPath = '/sys/class/gpio/gpio%d'; | |
const String _gpioDirection = '/sys/class/gpio/gpio%d/direction'; | |
const String _gpioValue = '/sys/class/gpio/gpio%d/value'; | |
const String _gpioActiveLow = '/sys/class/gpio/gpio%d/active_low'; | |
enum Direction { input, output, low, high } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { GetSignedUrlConfig, Storage, File, Bucket } from '@google-cloud/storage'; | |
const storage = new Storage({ | |
keyFilename: './config/creds.json', | |
}); | |
type UploadedFile = { | |
url: string; | |
bucketId: string; | |
bucketName: string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use .base | |
-- SQL password message: concat('md5', md5(concat(md5(concat(password, username)), random-salt))) | |
-- "md58393de45eea6f814e37f41f02540710c" | |
calculatePassword: Text -> Text -> Bytes -> Text | |
calculatePassword username password salt = | |
use md5 md5EncodeAscii md5Encode | |
userpassMd5 = md5EncodeAscii (password ++ username) | |
use Text toUtf8 | |
userpassMd5Bytes = (toUtf8 userpassMd5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Mongo | |
(require '[somnium.congomongo :as m]) | |
;; Products database | |
(def mongo-conn | |
(m/make-connection | |
"products" | |
:instances [{:host "127.0.0.1" :port 27017}])) | |
;; Set global connection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[etaoin.api :as d]) | |
;; Start firefox driver | |
(def driver (d/firefox {:headless false})) | |
;; Navigate to product url (loc key) | |
(d/go driver (:loc (cache->product "bellroy"))) | |
;; Query <script type="application/ld+json"> tags | |
(def ld-json-query {:tag :script :type "application/ld+json"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="application/ld+json"> | |
{ | |
"@context":"https://schema.org/", | |
"@type":"product", | |
"brand":"Bellroy", | |
"image":[...], | |
"name":"Lite Daypack", | |
"offers":[ | |
{ | |
"@type":"offer", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(clear-site "bellroy") ;; Clear cache first | |
(find-products "bellroy" "https://bellroy.com/sitemap.xml" product->cache) | |
(get-count "bellroy") | |
;; => 158 | |
;; Popping product links example: | |
(cache->product "bellroy") | |
;; => {:loc "https://bellroy.com/products/pod-jacket", ...} | |
(cache->product "bellroy") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[taoensso.carmine :as car]) | |
;; Redis Setup | |
(def redis-conn {:pool {} :spec {:uri "redis://localhost:6379/"}}) | |
(defmacro wcar* [& body] `(car/wcar redis-conn ~@body)) | |
(defn clear-site | |
[^String site] | |
(wcar* (car/del site))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
services: | |
redis: | |
image: 'bitnami/redis:latest' | |
container_name: redis | |
environment: | |
- ALLOW_EMPTY_PASSWORD=yes | |
ports: | |
- 6379:6379 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn get-content | |
[content] | |
(into {} (map (fn [c] [(:tag c) (first (:content c))]) (:content content)))) | |
(defn find-products | |
"Crawls the url's sitemap and for each product, will call f with the site and the product" | |
[site url f] | |
(let [p (parse-xml url) | |
tag (:tag p)] | |
(println (str "Parsing URL: " url " for site " site)) |
NewerOlder