Tuesday, October 4
Shadow

agist

super-hacky flask proxy

agist
# coding:utf-8 # Copyright 2011 litl, LLC. All Rights Reserved. import httplib import re import urllib import urlparse from flask import Blueprint, request, Response, url_for from werkzeug.datastructures import Headers from werkzeug.exceptions import NotFound from jiffy.admin.login import check_login proxy = Blueprint('proxy', __name__) proxy.before_request(check_login) HTML_REGEX = re.compile(r'((?:src|action|href)=["\'])/') JQUERY_REGEX = re.compile(r'(\$\.(?:get|post)\(["\'])/') JS_LOCATION_REGEX = re.compile(r'((?:window|document)\.location.*=.*["\'])/') CSS_REGEX = re.compile(r'(url\(["\']?)/') REGEXES = [HTML_REGEX, JQUERY_REGEX, JS_LOCATION_REGEX, CSS_REGEX] def iterform(multidict): for key in multidict.keys(): for value in multidict.getlist...

make a loop non-blocking with await new promise that resolves after a timeout

agist
// 28 aug 2022 // blocking vs awaiting // make a loop non-blocking with await new promise that resolves after a timeout function block(ms, pause) { return (async function (end) { end = ms + performance.now(); var ticks = 0; while(performance.now() < end) { pause && (await new Promise(res => setTimeout(res, 0))); ticks = 1 + ticks; } console.log({ ticks, pause }); return end; })(); } console.log("** one **"); block(1000).then((v) => { console.log("done"); console.warn(v) }); console.log("** two **"); block(1000, true).then((v) => { console.log("done"); console.warn(v) }); console.log("** end **"); /* ** one ** Object { ticks: 2152484, pause: undefined } ** two ** ** end ** done 1284703 undefined Object { ticks: 65, pause: tr...

JavaFX sample TableView with Add Buttons

agist
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; public class Person { private StringProperty firstName; private StringProperty lastName; public Person(String firstName, String lastName) { setFirstName(firstName); setLastName(lastName); } public final void setFirstName(String value) { firstNameProperty().set(value); } public final void setLastName(String value) { lastNameProperty().set(value); } public String getFirstName() { return firstNameProperty().get(); } public String getLastName() { return lastNameProperty().get(); } public StringProperty firstNameProperty() { if (firstName == null) firstName = new SimpleStringProperty(this, "firstName"); return firstName; } public StringProperty lastNamePrope...

To be imported with WP’s default import plugin

agist
<?xml version="1.0" encoding="UTF-8" ?> <!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. --> <!-- It contains information about your site's posts, pages, comments, categories, and other content. --> <!-- You may use this file to transfer that content from one site to another. --> <!-- This file is not intended to serve as a complete backup of your site. --> <!-- To import this information into a WordPress site follow these steps: --> <!-- 1. Log in to that site as an administrator. --> <!-- 2. Go to Tools: Import in the WordPress admin panel. --> <!-- 3. Install the "WordPress" importer from the list. --> <!-- 4. Activate & Run Importer. --> <!-- 5. Upload this file using the form provided on that page. --> ...

Allow any user to add comments 6

agist
## MORE CODE ABOVE <!-- Comments Area --> {{ ckeditor.load() }} {{ ckeditor.config(name='comment_text') }} {{ wtf.quick_form(form, novalidate=True, button_map={"submit": "primary"}) }} <div class="col-lg-8 col-md-10 mx-auto comment"> {% for comment in post.comments: %} <ul class="commentList"> <li> <div class="commenterImage"> <img src="https://pbs.twimg.com/profile_images/744849215675838464/IH0FNIXk.jpg"/> </div> <div class="commentText"> {{comment.text|safe}} ...

Protect Routes 2

agist
## MORE CODE ABOVE from functools import wraps from flask import abort #Create admin-only decorator def admin_only(f): @wraps(f) def decorated_function(*args, **kwargs): #If id is not 1 then return abort with 403 error if current_user.id != 1: return abort(403) #Otherwise continue with the route function return f(*args, **kwargs) return decorated_function @app.route("/new-post", methods=["GET", "POST"]) #Mark with decorator @admin_only def add_new_post(): form = CreatePostForm() if form.validate_on_submit(): new_post = BlogPost( title=form.title.data, subtitle=form.subtitle.data, body=form.body.data, img_url=form.img_url.data, author=curre...

oh-my-posh v8.33.2 – Passed – Package Tests Results

agist
<?xml version="1.0" encoding="utf-8"?> <registrySnapshot xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <user>S-1-5-21-1953236517-242735908-2433092285-500</user> <keys> <key installerType="InnoSetup" displayName="Oh My Posh version 8.33.2" displayVersion="8.33.2"> <RegistryView>Registry32</RegistryView> <KeyPath>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Oh My Posh_is1</KeyPath> <DefaultValue /> <InstallLocation><![CDATA[C:\Program Files (x86)\oh-my-posh\]]></InstallLocation> <UninstallString><![CDATA["C:\Program Files (x86)\oh-my-posh\unins000.exe" /SILENT]]></UninstallString> <HasQuietUninstall>...

React Deployment

agist
Deployment 1.Start the App--> npm start 2.Console should be clear 3.Browser Should be clear 4.Type--> npm run build 5.You will get a (build) Folder 6.Zip the build folder Command: sudo apt-get install zip -y zip -r build.zip build 7.Run Python Server Command: python3 -m http.server 8080 8.Open the Python Server in Browser and Download the build.zip file 9.Open your C-Panel File Manager 10.Open your domain public_html 11.Upload the build.zip 12.Extract it and move public_html 13.Deployment Done