Skip to content

Instantly share code, notes, and snippets.

@mkllnk
mkllnk / discover-api.conf
Created March 13, 2024 21:47
Nginx caching proxy config for Discover Regenerative API
proxy_cache_path /data/nginx/cache keys_zone=STATIC:500m;
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name discover.openfoodnetwork.org.au api.regenerative.org.au;
root /home/openfoodnetwork/apps/discover/current/public;
ssl_certificate /etc/letsencrypt/live/api.regenerative.org.au/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/api.regenerative.org.au/privkey.pem; # managed by Certbot
@mkllnk
mkllnk / i18n_lib.rb
Created April 14, 2023 05:42
I18n scope naming convention outside of views
# An idea for a convention. Not sure it will be useful yet.
module I18nLib
def lazy_translate(translation_key, options = {})
scope = self.class.to_s.underscore.tr("/", ".")
options.merge!(scope: scope)
I18n.t(translation_key, **options)
end
end
@mkllnk
mkllnk / output.csv
Last active August 4, 2022 00:22
Exporting in a format that's fit for importing products
producer sku name display_name category description units unit_type variant_unit_name price on_hand available_on on_demand shipping_category tax_category
Freddy's Farm Shop Fuji Apple Fruit 1 g 5.00 0 2022-07-27 01:59:03.412543 1 Default Tax Category
Freddy's Farm Shop Mushrooms Fungi 1 g 50.00 0 2022-07-27 01:59:03.540333 1 Default Tax Category
Fredo's Farm Hub Carrots Vegetables 1 g 3.00 0 2022-07-27 01:59:03.662664 1 Default Tax Category
Fredo's Farm Hub Potatoes Vegetables 1 g 2.00 0 2022-07-27 01:59:03.78174 1 Default Tax Category
Fredo's Farm Hub Tomatoes Vegetables 1 g 2.00 0 2022-07-27 01:59:03.900057 1 Default Tax Category
Fred's Farm TestSKU Garlic Vegetables 1 g 20.00 0 2022-07-27 01:59:03.212884 1 Default Tax Category
@mkllnk
mkllnk / ofn-global-stats.sh
Last active February 1, 2022 08:05
OFN global key stats
sql='
SELECT
SUBSTRING(CONCAT(completed_at) from 1 for 7) AS month,
COUNT(DISTINCT distributor_id) AS shops,
COUNT(DISTINCT email) AS customers,
COUNT(o.id) AS orders,
SUM(o.total) AS VALUE
FROM spree_orders o
WHERE o.completed_at >= DATE_TRUNC($$year$$, now() - interval $$2 months$$)
AND o.state = $$complete$$ GROUP BY month ORDER BY month;
@mkllnk
mkllnk / ofn-release-notes
Created May 15, 2020 05:00
Draft the next Open Food Network release
#!/bin/sh
git fetch upstream
latest="$(git tag --sort="-v:refname" | head -1)"
echo "Changes since last release $latest:"
pr_numbers() {
git log "$latest.." --merges --oneline |\
grep -oP 'Merge pull request #\K[0-9]+(?= from)'
enterprise = Enterprise.find_by_permalink("bawbawfoodhub")
scoper = OpenFoodNetwork::ScopeVariantToHub.new(enterprise)
#producer,distributor,name,display_name,variant_unit_name,sku,units,unit_type,price,on_hand,on_demand
data = enterprise.inventory_items.visible.map do |item|
variant = item.variant
scoper.scope(variant) if variant
product = variant&.product
{
producer: product&.supplier&.name,
@mkllnk
mkllnk / victorian-producers.rb
Created March 23, 2020 00:40
Producer export
producers = Enterprise.is_primary_producer.joins(:address).where(spree_addresses: {state_id: 1061493592}).map { |e| {id: e.id, name: e.name, contact: e.contact_name, phone: e.phone, email: e.email_address, properties: e.producer_properties.map(&:value).join("|")} }
CSV.open("producers.csv", "wb") { |csv| csv << producers.first.keys; producers.each { |p| csv << p.values } }
#!/usr/bin/env ruby
# Create CSV files for each producer in recently closed order cycles.
#
# It's similar data to the email sent to producers but as a CSV file.
#
# Use like this:
#
# bundle exec rails runner script/order_cycle_producer_csv.rb
./monthly-sales.sh `date --date "-1 month" +%Y-%m-01` `date +%Y-%m-01` > monthly-sales-`date --date "-1 month" +%Y-%m`.csv
@mkllnk
mkllnk / git-ftp-version
Created June 16, 2019 09:54
Script to update the version within several files of the Git-ftp project
#!/bin/sh
set -ex
test -w git-ftp
test -w tests/git-ftp-test.sh
test "$(git status -uno --porcelain | wc -l)" -eq 0
current="$(grep "\<VERSION='.*'" git-ftp | cut -d "'" -f2)"