Skip to content

Instantly share code, notes, and snippets.

@Fr6jDJF
Fr6jDJF / ddc-ci.py
Created May 23, 2016 10:02 — forked from vdcrim/ddc-ci.py
Python script for adjusting the settings of my monitor, by using DDC/CI
#!/usr/bin/env python3
"""
Show and adjust display parameters on an Iiyama ProLite XB2483HSU-B1 monitor
Requirements:
- mentioned monitor (27' should also work) with DDC/CI setting on
- Windows Vista+
- Python 3
@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_ = [
@sofaking
sofaking / reset_submodules.sh
Created November 23, 2017 16:22
Reset a git repository with submodules to initial state
git submodule foreach --recursive git reset --hard
git reset --hard
git submodule update --init
git submodule foreach --recursive git submodule update --init
@EricWF
EricWF / constinit.md
Last active July 16, 2020 09:07
A Proposal to add [[constinit]] to C++
Document Number: P1143r3
Date: 2019-06-18
Project: Programming Language C++, Evolution
Revises: P1143r2
Reply to: eric@efcs.ca

Adding the constinit keyword

@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":
@odarbelaeze
odarbelaeze / rand.cc
Last active March 25, 2021 11:15
Random number generator benchmarks
#include <cstdlib>
#include <iostream>
#include <chrono>
#include <random>
#include<gsl/gsl_rng.h>
class Timer
{
private:
@hmanicka
hmanicka / app.py
Last active April 30, 2021 15:22
Flask-Admin: To update timestamp with timezone field with UTC
import pytz
class MyView(MyModelView):
# Display the time in user's local timezone on the List View
column_formatters =
dict(scheduledtime=lambda v,c,m,p: m.scheduledtime.replace(tzinfo=pytz.utc).astimezone(tz=pytz.timezone(config.LOCAL_TIMEZONE)))
# Display the time in user's timezone on the Edit View
def edit_form(self, obj):
form = self._edit_form_class(get_form_data(), obj=obj)
@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]
@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;
@absent1706
absent1706 / sqlalchemy-truncate_db.py
Last active April 5, 2023 03:50
Sqlalchemy: Truncate all tables
def truncate_db(engine):
# delete all table data (but keep tables)
# we do cleanup before test 'cause if previous test errored,
# DB can contain dust
meta = MetaData(bind=engine, reflect=True)
con = engine.connect()
trans = con.begin()
con.execute('SET FOREIGN_KEY_CHECKS = 0;')
for table in meta.sorted_tables:
con.execute(table.delete())