Skip to content

Instantly share code, notes, and snippets.

View jniemann66's full-sized avatar

Judd Niemann jniemann66

  • Melbourne
View GitHub Profile
@jniemann66
jniemann66 / flashingpushbutton.h
Created April 7, 2016 05:05
Making a flashing button in Qt
#ifndef FLASHINGPUSHBUTTON_H
#define FLASHINGPUSHBUTTON_H
#include <QPushButton>
#include <QTimer>
// class flashingPushButton
// Description: a QPushButton which flashes on and off whenever it is Disabled (to indicate that the app is busy processing ...)
class flashingPushbutton : public QPushButton{
@jniemann66
jniemann66 / mainwindow.cpp
Created April 7, 2016 06:43
Qt: populating QCombox items using std output from external process
// Launch external process, and populate QComboBox using output from the process:
void MainWindow::PopulateBitFormats(const QString& fileName)
{
QProcess ConverterQuery;
ui->BitDepthCombo->clear();
int extidx = fileName.lastIndexOf(".");
if(extidx > -1){
QString ext = fileName.right(fileName.length()-extidx-1); // get file extension from filename
ConverterQuery.start(ConverterPath, QStringList() << "--listsubformats" << ext); // ask converter for a list of subformats for the given file extension
// Parenthesis.cpp : calculate all expressions containing n pairs of matched parentheses ...
//
#include <string>
#include <iostream>
void brackets(int availableOpenBrackets, int availableCloseBrackets, std::string s, int& combinationCount);
int main()
{
@jniemann66
jniemann66 / testAVX.cpp
Created October 3, 2016 22:10
runtime check of CPU AVX capabilities
#include <iostream>
#include <immintrin.h>
// Verify CPU capabilities:
bool bAVXok = false;
int cpuInfo[4] = { 0,0,0,0 };
__cpuid(cpuInfo, 0);
if (cpuInfo[0] != 0) {
__cpuid(cpuInfo, 1);
if (cpuInfo[2] & (1 << 28)) {
@jniemann66
jniemann66 / isMSIE.js
Created October 3, 2016 22:12
detecting Internet Explorer
function isBrowserIE() {
var ua = window.navigator.userAgent;
var rv = false;
if (ua.indexOf('MSIE ') > 0) { // IE 10 or older
rv = true;
}
if (ua.indexOf('Trident/') > 0) { // IE 11
rv = true;
@jniemann66
jniemann66 / DecimalToRoman.cpp
Created October 3, 2016 22:16
decimal to roman numerals
// DecimalToRoman.cpp : convert decimal number to Roman Numeral
#include <iostream>
#include <string>
#include <vector>
struct symbol {
std::string name;
int value;
};
@jniemann66
jniemann66 / testlinecircleintersection.js
Last active October 4, 2016 01:04
test whether line intersects with circle
///////////////////////////////////////////////////////////////////////////////
// testLineCircleIntersection() : test whether a line intersects with a circle
// x0,y0 : first point on line
// x1,y1 : second point on line
// ox,oy : center of circle
// r: radius of circle
//
// return value:
// < 0 : no intersection,
// = 0 : tangent (hits circle at one point),
@jniemann66
jniemann66 / 0_reuse_code.js
Created November 3, 2016 00:35
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jniemann66
jniemann66 / array_merge.js
Created November 3, 2016 00:52
Merging array of arrays into a single array
// merge array of arrays into a single array
var data = [
['a','b','c'],
['d','e','f'],
['g','h','i'],
]; // array of arrays
// merge results into a single array
var combinedData = [].concat.apply([], data); // ['a','b','c','d' ... 'i']
@jniemann66
jniemann66 / datepicker-iso8601.js
Last active April 9, 2017 12:23
installing a jQueryUI datepicker with internal ISO date format, but different display format
// detect if datepicker required (no input type="date" ...)
if ( $('[type="date"]').prop('type') != 'date' ) {
installDatePicker('dd-M-yy'); // note: with jQui datepicker, 'yy' is 4-digit year
}
// installs a jQueryUI datepicker in place of <input type="date">:
function installDatePicker(displayFormat) {
$('input[type=date]').each(function (index, element) {
var hiddenDate = $(this).clone().insertAfter(this).hide(); // create hidden date field that will contain the iso 8601 date format