Skip to content

Instantly share code, notes, and snippets.

View jniemann66's full-sized avatar

Judd Niemann jniemann66

  • Melbourne
View GitHub Profile
@jniemann66
jniemann66 / update-vscode.sh
Created November 11, 2017 09:45
update vscode on ubuntu
#!/usr/bin/env bash
#https://askubuntu.com/questions/833448/how-to-update-vs-code-on-ubuntu
wget https://vscode-update.azurewebsites.net/latest/linux-deb-x64/stable -O /tmp/code_latest_amd64.deb
sudo dpkg -i /tmp/code_latest_amd64.deb
@jniemann66
jniemann66 / wav2spectrum.py
Last active November 26, 2017 04:15
show impulse response as spectrum (no windowing)
# -*- coding: utf-8 -*-
"""
Read a 32-bit (!) wave file and plot frequency response
"""
import numpy as np
import matplotlib.pyplot as plt
import wave
import sys
import os
@jniemann66
jniemann66 / kinetic.cpp
Created February 2, 2018 03:24
Qt: Adding Kinetic Scrolling to QTableView / QTableWidget for iPad
#include <QHeaderView>
#include <QScroller>
#include <QScrollBar>
// ... //
// in someWidget with someView (typical settings, not mandatory):
someView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
someView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
someView->horizontalScrollBar()->setDisabled(true);
@jniemann66
jniemann66 / multilinetextdialog.cpp
Created February 7, 2018 01:33
Qt Generic Multiline Text Edit Dialog Boilerplate
#include "multilinetextdialog.h"
#include <QVBoxLayout>
#include <QDialogButtonBox>
#include <QPushButton>
MultilineTextDialog::MultilineTextDialog(QWidget *parent) : QDialog(parent)
{
// allocate widgets
heading = new QLabel;
textEdit = new QTextEdit(this);
@jniemann66
jniemann66 / datetime.cpp
Created March 1, 2018 03:43
Qt: Convert QDateTime to ISO Date Time with Timezone
// get timezone offset in seconds
int offsetSeconds = QTimeZone::systemTimeZone().offsetFromUtc(QDateTime::currentDateTime());
// format an ISO Date & Time with Timezone. eg "2018-03-21T13:04:00+11:00"
QDateTime selectedDateTime = QDateTime(calendarWidget->selectedDate(), timeEdit->time(), Qt::OffsetFromUTC, offsetSeconds);
qDebug() << selectedDateTime.toString(Qt::ISODate);
@jniemann66
jniemann66 / appointmentwidget.h
Last active April 22, 2018 22:55
Qt Appointment/Diary Widget
#ifndef APPOINTMENTWIDGET_H
#define APPOINTMENTWIDGET_H
// AppointmentWidget.h : basic appointment (Diary) widget
// (implementation in header)
#include <QWidget>
#include <QStringList>
#include <QTime>
#include <QTimer>
@jniemann66
jniemann66 / trapfpexception.cpp
Created March 19, 2018 11:51
Trap floating point exceptions with MSVC
#if defined(_DEBUG) && defined(_MSC_VER)
// use this to trap floating-point exceptions (MSVC: compile with /fp:strict)
#include <float.h>
unsigned int fp_control_state = _controlfp(_EM_INEXACT, _MCW_EM);
#endif
@jniemann66
jniemann66 / factorial.h
Created March 25, 2018 03:03
Factorial lookup table constants (double and quad precision)
// factorial.h : table of factorial constants
// note: to use quad-precision with GCC, compile with
// -std=gnu++11 -lquadmath
#ifndef FACTORIAL_H
#define FACTORIAL_H
#define FACTORIAL_TABLE_DOUBLE_COUNT 60
#define FACTORIAL_TABLE_QUAD_COUNT 170
@jniemann66
jniemann66 / qdirtrick.cpp
Created April 12, 2018 11:43
QT check and create dir, including intermediates
QDir dir("path/to/dir");
if (!dir.exists()) {
dir.mkpath(".");
}
@jniemann66
jniemann66 / qscroller-fix.cpp
Last active April 23, 2018 09:05
Qt fix clash between QScroller and QScrollBar
// The trick is to call grabGesture() on the widget's viewport() instead of the whole widget itself
// eg:
// Add kinetic scroller to converter output
QScroller::grabGesture(ui->ConverterOutputText->viewport(), QScroller::LeftMouseButtonGesture);
// ... instead of
// QScroller::grabGesture(ui->ConverterOutputText, QScroller::LeftMouseButtonGesture);