Skip to content

Instantly share code, notes, and snippets.

View zhiwehu's full-sized avatar

Jeffrey Hu zhiwehu

View GitHub Profile
@zhiwehu
zhiwehu / pyodide-provider.js
Created January 28, 2022 16:50 — forked from lambertbrady/pyodide-provider.js
Pyodide React Component
import { createContext, useRef, useState } from 'react'
export const PyodideContext = createContext()
export default function PyodideProvider({ children }) {
const pyodide = useRef(null)
const hasLoadPyodideBeenCalled = useRef(false)
const [isPyodideLoading, setIsPyodideLoading] = useState(true)
return (
@zhiwehu
zhiwehu / snapshot-shortcut-setting.sh
Created August 25, 2019 10:27 — forked from Naohiro2g/snapshot-shortcut-setting.sh
This script changes the keybinding for scrot to raspi2png.
echo '#!/bin/sh' >/home/pi/r2p.sh
echo >>/home/pi/r2p.sh
echo '/home/pi/raspi2png-master/raspi2png --pngname /home/pi/Pictures/$(date +snapshot-%Y%m%d-%H%M%S.png)' >>/home/pi/r2p.sh
sed -i.bak 's/scrot/sh \/home\/pi\/r2p.sh/g' /home/pi/.config/openbox/lxde-pi-rc.xml
openbox --reconfigure
#!/bin/bash
NAME="hello_app" # Name of the application
DJANGODIR=/webapps/hello_django/hello # Django project directory
SOCKFILE=/webapps/hello_django/run/gunicorn.sock # we will communicte using this unix socket
USER=hello # the user to run as
GROUP=webapps # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=hello.settings # which settings file should Django use
DJANGO_WSGI_MODULE=hello.wsgi # WSGI module name
import base64
import cStringIO
from django.core.files.uploadedfile import InMemoryUploadedFile
# ...
if request.POST.get('file') and request.POST.get('name'):
file = cStringIO.StringIO(base64.b64decode(request.POST['file']))
image = InMemoryUploadedFile(file,
field_name='file',
import mongoengine
class MongoModelSerializer(serializers.ModelSerializer):
def get_default_fields(self):
cls = self.opts.model
opts = get_concrete_model(cls)
#pk_field = opts.pk
fields = []
fields += [getattr(opts, field) for field in opts._fields]
#fields += [field for field in opts.many_to_many if field.serialize]
@zhiwehu
zhiwehu / oauth-twitter.py
Created August 21, 2012 03:19 — forked from hktechn0/oauth-twitter.py
OAuth for Twitter
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import time, random
import urllib, urllib2
import hmac, hashlib
import cgi
#
# OAuth Module for Twitter
"""
jQuery templates use constructs like:
{{if condition}} print something{{/if}}
This, of course, completely screws up Django templates,
because Django thinks {{ and }} mean something.
Wrap {% verbatim %} and {% endverbatim %} around those
blocks of jQuery templates and this will try its best