Skip to content

Instantly share code, notes, and snippets.

@dcoles
dcoles / xinput.py
Created December 26, 2012 07:15 — forked from anonymous/xinput.py
# Simple Wrapper around XInput API
#
# Author: David Coles <coles.david@gmail.com>
import ctypes
from ctypes.wintypes import BYTE, WORD, SHORT, DWORD
class XInputGamepad(ctypes.Structure):
_fields_ = [
@ashwin
ashwin / ThrustRandom.cu
Created October 31, 2013 06:20
How to generate random numbers using Thrust
#include <thrust/device_vector.h>
#include <thrust/random.h>
struct GenRand
{
__device__
float operator () (int idx)
{
thrust::default_random_engine randEng;
thrust::uniform_real_distribution<float> uniDist;
@rdb
rdb / js_winmm.py
Last active February 17, 2024 10:04
Access game controllers from Python on Windows via the WinMM API. See https://discourse.panda3d.org/t/game-controllers-on-windows-without-pygame/14129
# Released by rdb under the Unlicense (unlicense.org)
# Further reading about the WinMM Joystick API:
# http://msdn.microsoft.com/en-us/library/windows/desktop/dd757116(v=vs.85).aspx
from math import floor, ceil
import time
import ctypes
import _winreg as winreg
from ctypes.wintypes import WORD, UINT, DWORD
from ctypes.wintypes import WCHAR as TCHAR
@nicktoumpelis
nicktoumpelis / repo-rinse.sh
Created April 23, 2014 13:00
Cleans and resets a git repo and its submodules
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
@mekza
mekza / countries.py
Last active December 23, 2022 23:04
WTForms Select Field for country
from wtforms import SelectField
import pycountry
class CountrySelectField(SelectField):
def __init__(self, *args, **kwargs):
super(CountrySelectField, self).__init__(*args, **kwargs)
self.choices = [(country.alpha_2, country.name) for country in pycountry.countries]
@pawl
pawl / override_get_query.py
Created September 10, 2014 18:58
Override get_query based on GET parameter - Flask-Admin
from application import db
from application.views.modelview import ModelView
from application.models import Things # has an attribute called thing_type
class MyModelView(ModelView):
def get_query(self):
thing_type = request.args.get('type', None) # pretending we have a GET parameter called "type"
if thing_type == "type1":
return super(ModelView, self).get_query().filter(Things.thing_type.like('type1 %'))
elif thing_type == "type2":
@georgy7
georgy7 / extract_mbox_attachments.py
Last active June 6, 2024 22:08
Extract attachments from mbox file.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Modified.
# Original script source:
# http://blog.marcbelmont.com/2012/10/script-to-extract-email-attachments.html
# https://web.archive.org/web/20150312172727/http://blog.marcbelmont.com/2012/10/script-to-extract-email-attachments.html
# Usage:
# Run the script from a folder with file "all.mbox"
@CoolOppo
CoolOppo / optimal-video-to-gif-imagemagick.md
Last active June 29, 2024 10:33
Converting videos to GIFs optimally using ImageMagick

ImageMagick Video to GIF Optimization Summary

A software developer who uses IM to create Movie GIFs, Benoit Rouleau, in discussion with me, gave me a AVI video of a plane flying over, to help us mutually explore IM video conversion techniques.

However while the AVI itself is quite small, the uncompressed video is a

@iamtekeste
iamtekeste / Download Google Drive files with WGET
Created July 8, 2015 11:00
Download Google Drive files with WGET
Download Google Drive files with WGET
Example Google Drive download link:
https://docs.google.com/open?id=[ID]
To download the file with WGET you need to use this link:
https://googledrive.com/host/[ID]
Example WGET command:
@doobeh
doobeh / bulk_updates_sqlalchemy.py
Created September 8, 2015 18:24
SQLAlchemy bulk updates.
""" Quick example showing how to do a bulk update into the database
using SQLAlchemy, without interacting heavily with the ORM.
"""
from sqlalchemy.sql.expression import bindparam
stmt = addresses.update().\
where(addresses.c.id == bindparam('_id')).\
values({
'user_id': bindparam('user_id'),
'email_address': bindparam('email_address'),