Skip to content

Instantly share code, notes, and snippets.

View allanlei's full-sized avatar
:shipit:
What's up?

Allan Lei allanlei

:shipit:
What's up?
View GitHub Profile
@allanlei
allanlei / dh.py
Created April 24, 2014 15:28
Diffie Hellman
#!/usr/bin/env python
from binascii import hexlify
import hashlib
# If a secure random number generator is unavailable, exit with an error.
try:
import Crypto.Random.random
secure_random = Crypto.Random.random.getrandbits
except ImportError:
@allanlei
allanlei / README.md
Created March 23, 2023 15:51
GKE nvidia driver installer with driver version control

Find the corresponding nvidia driver for COS

  1. gsutil ls gsutil ls gs://cos-tools-asia/${COS_VERSION}/extensions/gpu
  2. Pick an available version and update annotations.version

Creating a Node pool with a specific driver

  1. Create nodepool with taint nvidia.com/gpu-driver-version=DRIVER_VERSION_MAJOR
  2. Create corresponding daemonset driver installer with nvidia.com/gpu-driver-version=DRIVER_VERSION_MAJOR
@allanlei
allanlei / fields.py
Created January 10, 2013 07:58
Subclass of mongoengine's GenericEmbeddedDocumentField. Allows GenericEmbeddedDocumentField to read a custom field instead of _cls to construct the EmbeddedDocument.
from mongoengine.fields import GenericEmbeddedDocumentField as MDBGenericEmbeddedDocumentField
class GenericEmbeddedDocumentField(MDBGenericEmbeddedDocumentField):
def __init__(self, *args, **kwargs):
self.cls_field = kwargs.pop('cls_field', '_cls')
super(GenericEmbeddedDocumentField, self).__init__(*args, **kwargs)
def to_python(self, value):
cls = None
if isinstance(self.cls_field, (str, unicode)):
@allanlei
allanlei / blur.sh
Last active September 7, 2022 18:34
Pulsating Blur
ffmpeg -stream_loop -1 -i bbb.mp4 -filter_complex "\
[0:v]split=2[base][overlay];
[overlay]gblur=5,format=yuva444p,geq=r='r(X,Y)':a='abs(255*sin(T))'[overlay];
[base][overlay]overlay[out]" \
-map "[out]" output.mp4
@allanlei
allanlei / daemonset-preloaded.yaml
Created June 26, 2020 05:40
Custom Driver Install for NVIDIA on GKE
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: nvidia-driver-installer-cos
namespace: kube-system
labels:
k8s-app: nvidia-driver-installer-cos
spec:
selector:
matchLabels:
@allanlei
allanlei / gist:8ea15ceeae93447f7212
Created July 16, 2014 03:31
Running twisted application without twistd
from twisted.web.resource import Resource
from twisted.internet import reactor
from twisted.web.static import File
from twisted.web import server
from twisted.application import internet, service
from twisted.application.app import startApplication
from twisted.web.wsgi import WSGIResource
from twisted.runner.procmon import ProcessMonitor
from twisted.web import vhost, static
@allanlei
allanlei / ffmpeg-blurout.sh
Last active September 24, 2021 02:24
FFmpeg Filtergraph to generate Blur Out
ffmpeg -i source.mp4 -filter_complex \
"[0:v]split=2[base][blurred]; \
[blurred]boxblur=luma_radius=50:chroma_radius=25:luma_power=1[blurred]; \
[blurred]fade=type=in:start_time=5:duration=1:alpha=1[blurred-with-fadein]; \
[base][blurred-with-fadein]overlay[blurout]" \
-map "[blurout]" blurout.mp4
@allanlei
allanlei / README.md
Last active September 9, 2021 15:50
openssl smime sign with `nodetach`

This is the rough equivalent of

openssl smime -sign
    -signer cert.crt
    -inkey cert.key
    -certfile intermediate.pem 
    -nodetach 
    -outform der 
    -in mdm.mobileconfig 
 -out mdm-signed.mobileconfig
@allanlei
allanlei / publish.py
Created February 26, 2016 05:09
MQTT Example
import paho.mqtt.client as mqtt
client = mqtt.Client(protocol=mqtt.MQTTv311)
client.connect('iot.eclipse.org', port=1883, keepalive=60)
client.publish('update', 'hello world')
@allanlei
allanlei / ffmpeg-scale-npp
Created June 26, 2020 05:04
FFMPEG using scale_npp
ffmpeg \
-vsync 0 \
-hwaccel cuvid -c:v h264_cuvid \
-i https://twitch-event-engineering-public.s3.amazonaws.com/sync-footage/Sync-Footage-V1-H264.mp4 \
-filter_complex " \
[0:v]scale_npp=1280:720[out]
" -map '[out]' -y -c:v h264_nvenc -y output.mp4