Skip to content

Instantly share code, notes, and snippets.

@benjclark
benjclark / gist:e989373008ce935ef5509f5f61a3637e
Created October 28, 2020 14:09
colorspace css refactor
<style>
#color_analysis_content .card {
height: 300px;
justify-content: space-between;
}
</style>
<div id="color_analysis_content" ic-get-from="/data/r_analysis/recolor/ICDB000060/rondoni_HT_dors_comp.tif/" ic-trigger-on="load" class="mt-2" ic-src="/data/r_analysis/recolor/ICDB000060/rondoni_HT_dors_comp.tif/" ic-deps="ignore" ic-id="2">
<div class="row">
<!-- Original image -->
<div class="col-12 col-sm-6 col-lg-2">
@benjclark
benjclark / random-insect-name-fetch.js
Last active May 12, 2020 20:01
Reproducing intercooler.js functionality in plain ES6 for the random insect name endpoint
/**
*
* Simple reproduction of what you are doing with intercooler.js for your random insect button
* Written in ES6 javascript, i.e. will not work in some older browsers but can be written with more verbose syntax to do so if needed
* It uses the modern method of retrieving data via xhr called 'fetch' which is asynchronous and returns a promise which is what the .then() is about. You don't need to understand how promises work for now but just know that they allow asynchronous code execution. I can explain more if needed.
* You can include this js in a <script> on the page or put it in a js file and load that file on your page
* This code could be updated with a little more syntax to turn it in to a module as in the end you will likely have different modules that you want to all load in to one single js file for your page
*/
// store the random insect button in a variable (you will need to add the attribute 'data-rand-insect-btn' to the <a> in your template)
@Maescool
Maescool / docker-compose.yml
Last active April 9, 2023 18:31
Traefik V2 docker-compose example with dashboard and SSL
version: '3.3'
services:
traefik:
# The official v2.0 Traefik docker image
image: traefik:v2.0
container_name: traefik
restart: unless-stopped
security_opt:
- no-new-privileges:true
/**
* Export all data from an IndexedDB database
*
* @param {IDBDatabase} idbDatabase The database to export from
* @return {Promise<string>}
*/
export function exportToJson(idbDatabase) {
return new Promise((resolve, reject) => {
const exportObject = {}
if (idbDatabase.objectStoreNames.length === 0) {
@stewartadam
stewartadam / main.py
Last active September 9, 2024 12:41 — forked from gear11/main.py
Simple Python proxy server based on Flask and Requests with support for GET and POST requests.
"""
A simple proxy server, based on original by gear11:
https://gist.github.com/gear11/8006132
Modified from original to support both GET and POST, status code passthrough, header and form data passthrough.
Usage: http://hostname:port/p/(URL to be proxied, minus protocol)
For example: http://localhost:5000/p/www.google.com
"""
import re
@malexer
malexer / sqlalchemy_upsert.py
Last active January 26, 2024 14:09
Modelling UPSERT in SQLAlchemy (well actually it is not upsert but speed improvement is significant in comparison with simple session.merge)
# Note: it is a copy of great answer by "mgoldwasser" from Stackoverflow
# Check the original answer here: http://stackoverflow.com/a/26018934/1032439
# Imagine that post1, post5, and post1000 are posts objects with ids 1, 5 and 1000 respectively
# The goal is to "upsert" these posts.
# we initialize a dict which maps id to the post object
my_new_posts = {1: post1, 5: post5, 1000: post1000}
for each in posts.query.filter(posts.id.in_(my_new_posts.keys())).all():
@doobeh
doobeh / home.html
Created January 19, 2016 14:04
More complete example of FieldList with FormField
<form method="post" action="">
{{ form.name}}
{{ form.hidden_tag() }}
<br/>
{% for entry in form.hours %}
{{ loop.index0|dow }}
{{ entry() }}
{% endfor %}
<input type="submit"/>
</form>
@spalladino
spalladino / mysql-docker.sh
Created December 22, 2015 13:47
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@developius
developius / README.md
Last active March 14, 2025 17:38
Setup SSH keys for use with GitHub/GitLab/BitBucket etc
@fanzeyi
fanzeyi / app.py
Created November 15, 2013 19:17
Simple stream file proxy with Flask and Requests
# -*- coding: utf-8 -*-
from flask import Flask
from flask import Response
from flask import stream_with_context
import requests
app = Flask(__name__)