Skip to content

Instantly share code, notes, and snippets.

View cestrand's full-sized avatar
👖

Marcin Kolenda cestrand

👖
View GitHub Profile
@cestrand
cestrand / lwjgl_draw_triangle.kt
Created December 16, 2020 13:03
Draw colorful triangle using LWJGL and OpenGL 1.1
// https://www.lwjgl.org/guide copy-pasted to JetBrains IDEA to convert syntax from Java to Kotlin.
// LWJGL 3 version 3.2.3
import org.lwjgl.Version
import org.lwjgl.glfw.*
import org.lwjgl.glfw.Callbacks.*
import org.lwjgl.glfw.GLFW.*
import org.lwjgl.opengl.*
import org.lwjgl.opengl.GL11.*
import org.lwjgl.system.MemoryStack
import org.lwjgl.system.MemoryUtil
@cestrand
cestrand / opengl_version.kt
Created December 16, 2020 12:17
Print supported OpenGL API's to standard output up to OpenGL 4.6.
/**
* Print supported OpenGL API's to standard output up to OpenGL 4.6.
*
* @author Marcin Kolenda
*/
import org.lwjgl.glfw.GLFW
import org.lwjgl.opengl.GL
import org.lwjgl.opengl.GLCapabilities
import org.lwjgl.system.MemoryUtil
@cestrand
cestrand / gauss.lsp
Last active October 20, 2019 20:13
(defpackage :cl-gauss-elimination
(:use :cl))
(in-package :cl-gauss-elimination)
(defun solve-upper (U)
(let* ((d (array-dimension U 0))
(x (make-array (list d) :initial-element 0)))
(loop for i from (1- d) downto 0
do (setf (aref x i)
@cestrand
cestrand / StringEnumController.java
Created March 30, 2018 08:09
Java's `enum` on String values
package com.company;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.atomic.AtomicLong;
@cestrand
cestrand / getopts-ab-option.hs
Last active December 23, 2017 12:23
[Haskell] getopts-ab-option
module Main where
import System.Console.GetOpt
import System.Environment
data Flag = OptionA | OptionB
options :: [OptDescr Flag]
options =
[ Option ['a'] [] (NoArg OptionA) "Option A"
, Option ['b'] [] (NoArg OptionB) "Option B"
class RandomCollection(UserList):
def get_random(self):
"""Get randomly element from this collection"""
max_it = len(self.data) - 1
return self.data[randint(0, max_it)]
def random_boolean(probability=None):
if probability:
@cestrand
cestrand / 0_reuse_code.js
Created August 3, 2017 20:11
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
@cestrand
cestrand / mainwindow.cpp
Created August 16, 2015 10:32
Add clickable image banner in QToolBar
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow)
{
// somewhere after ui->setupUi(this);
ui->mainToolBar->addWidget(spacer);
ui->mainToolBar->addWidget(new MyClickableBanner(this));
// ...
}
@cestrand
cestrand / main.cpp
Created August 15, 2015 23:32
KDE Plasma 4 applet template for Qt Creator
#include "main.h"
#include <QPainter>
#include <plasma/theme.h>
MyPlasmaApplet::MyPlasmaApplet(QObject *parent, const QVariantList &args) : Plasma::Applet(parent, args)
{ // rather don't add other stuff here. Use init() instead
setBackgroundHints(DefaultBackground);
@cestrand
cestrand / mywidget.cpp
Created August 15, 2015 20:52
Qt - custom context menu
#include <QMenu>
#include <QAction>
MyWidget::MyWidget(QWidget* parent) : QWidget(parent)
{
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuShow(QPoint)));
}
void MyWidget::customContextMenuShow(const QPoint& pos)