Skip to content

Instantly share code, notes, and snippets.

View abulka's full-sized avatar
🤔
Prototyping an online, low code IDE

Andy Bulka abulka

🤔
Prototyping an online, low code IDE
View GitHub Profile
# Auto list fields from django models - from https://djangosnippets.org/snippets/2533/#c5977
import inspect
from django.utils.html import strip_tags
from django.utils.encoding import force_text
def process_docstring(app, what, name, obj, options, lines):
# This causes import errors if left outside the function
from django.db import models
@abulka
abulka / index.html
Created August 14, 2018 03:47
Electron Fiddle Gist
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<!--In Electron, this is the correct way to include jQuery-->
<script>window.$ = window.jQuery = require('https://code.jquery.com/jquery-3.3.1.slim.min.js');</script>
</head>
@abulka
abulka / request-logging-middleware.py
Last active October 20, 2018 08:00
RequestLoggingMiddleware
from django.conf import settings
from django.db import connection
import logging
import time
from django.utils.deprecation import MiddlewareMixin
log = logging.getLogger(__name__)
class RequestLoggingMiddleware(MiddlewareMixin):
@abulka
abulka / index.js
Created December 7, 2018 04:49
bootstrapping code for launching python from electron when packaged inside pyinstaller directory structure
import { app, BrowserWindow, Menu, MenuItem, globalShortcut } from 'electron';
const {ipcMain} = require('electron'); // do not use ipcRenderer in main process, use ipcMain
const path = require('path')
const url = require('url')
const log = require('electron-log'); // https://www.npmjs.com/package/electron-log
const sh = require("shelljs"); // https://github.com/shelljs/shelljs
log.transports.file.level = 'debug'; // transports: console and file, levels: error, warn, info, verbose, debug, silly
log.transports.console.level = 'warn';
@abulka
abulka / version-check.py
Created March 1, 2019 06:14
Check for latest app version asynchronously inside wxPython app
import asyncio
import aiohttp
from async_lru import alru_cache
@alru_cache(maxsize=32)
async def url_to_data(url):
timeout = aiohttp.ClientTimeout(total=60)
async with aiohttp.ClientSession(timeout=timeout) as session:
async with session.get(url) as response:
return await response.read(), response.status
@abulka
abulka / turtle_avoidance.py
Last active March 2, 2019 01:04
Complete wxasync wxPython app which avoids the turtle problem
import wx
from wxasync import AsyncBind, WxAsyncApp, StartCoroutine
import asyncio
from asyncio.events import get_event_loop
import time
import wx.lib.newevent
SomeNewEvent, EVT_SOME_NEW_EVENT = wx.lib.newevent.NewEvent()
SomeNewEventAsync, EVT_SOME_NEW_EVENT_ASYNC = wx.lib.newevent.NewEvent()
@abulka
abulka / async-custom-events.py
Created March 2, 2019 00:55
Defining and raising a custom wxPython event which triggers an async function
# define custom event
SomeNewEventAsync, EVT_SOME_NEW_EVENT_ASYNC = wx.lib.newevent.NewEvent()
# define which async function to call when the event happens
AsyncBind(EVT_SOME_NEW_EVENT_ASYNC, self.async_callback, self)
# Create and post the event
evt = SomeNewEventAsync(attr1="hello", attr2=654)
wx.PostEvent(self, evt)
@abulka
abulka / rubber_band_async.py
Created March 2, 2019 01:39
Rubber band asynchronous wxPython app
import wx
import time
from wxasync import AsyncBind, WxAsyncApp, StartCoroutine
import asyncio
from asyncio.events import get_event_loop
ASYNC_VERSION = True
class SelectableFrame(wx.Frame):
@abulka
abulka / snapcraft_eg1.yaml
Created March 21, 2019 04:38
Including the wxPython dependency into snapcraft.yaml
python-packages:
- https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04/wxPython-4.0.4-cp36-cp36m-linux_x86_64.whl
- wxasync
@abulka
abulka / snapcraft_eg2.yaml
Created March 21, 2019 04:40
wxPython dependencies for snapcraft.yaml
desktop-gtk3:
build-packages:
- build-essential
- libgtk-3-dev
make-parameters:
- FLAVOR=gtk3
plugin: make
source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
source-subdir: gtk
stage-packages: