Skip to content

Instantly share code, notes, and snippets.

View jnareb's full-sized avatar

Jakub Narębski jnareb

View GitHub Profile
@jnareb
jnareb / listings_settings_pl.tex
Last active January 29, 2020 17:13
Konfiguracja pakietu listings: kolorowanie składni, polskie literki, numerowanie linii, itp.
%%% Proszę zwrócić uwagę na komentarze! %%%
%% fonty programistyczne, o stałej szerokości znaków
%% jeden z poniższych
\ifcase 0 % 0-3
% 0
%% użycie domyślnego fontu o stałej szerokości znaków (monospace)
\or % 1
%% dosyć wąski font stałej szerokości Inconsolata, do druku kodu
%% niestety bez czcionki pochyłej w foncie
@jnareb
jnareb / mainwindow.cpp
Created May 18, 2019 17:17
Ładowanie obrazów w Qt z pliku zewnętrznego do istniejącego QImage
void MainWindow::loadImageFromFile(QString filename, QImage *dstImage)
{
QImage *tempImage = new QImage(filename);
*dstImage = tempImage->copy(0,0,dstImage->width(),dstImage->height());
delete tempImage;
}
void MainWindow::openImageFile(QImage *dstImage)
{
QString filename = QFileDialog::getOpenFileName(
@jnareb
jnareb / mainwindow.cpp
Created May 18, 2019 09:45
Nieblokujące opóźnienie w aplikacjach napisanych za pomocą biblioteki Qt (np. do animacji)
void MainWindow::delay(int ms)
{
QTime endTime = QTime::currentTime().addMSecs(ms);
while (QTime::currentTime() < endTime)
QCoreApplication::processEvents(QEventLoop::AllEvents, 100 /* maxtime in ms */);
}
@jnareb
jnareb / for-edition-40.md
Created May 16, 2018 11:53
Serialized Commit Graph sketch - for Git Rev News
@jnareb
jnareb / max_macro.c
Created March 15, 2018 08:20
max() preprocessor macro with single-evaluation, constant expression for constants
/* https://lwn.net/Articles/748870/ */
#define __single_eval_max(t1, t2, max1, max2, x, y) ({ \
t1 max1 = (x); \
t2 max2 = (y); \
(void) (&max1 == &max2); \
max1 > max2 ? max1 : max2; })
#define __max(t1, t2, x, y) \
__builtin_choose_expr(__builtin_constant_p(x) && \
@jnareb
jnareb / .console
Created July 12, 2017 18:21
`git --force-with-lease` zapobiega nadpisaniu czyichś zmian
$ git push
To https://git.company.com/repo.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://git.company.com/repo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
@jnareb
jnareb / .console
Created July 12, 2017 17:41
Przykładowy wynik udanego wykonania operacji `git push --force-with-lease` w sytuacji non-fast-forward.
$ git push --force-with-lease
Counting objects: 3, done.
Writing objects: 100% (3/3), 269 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://git.company.com/repo.git
+ 3fb00bd...8d110bd master -> master (forced update)
@jnareb
jnareb / .console
Created July 12, 2017 17:01
Git nie pozwala wykonać `git push` ponieważ repozytorium nie jest w sytuacji fast-forward
$ git commit -a --amend
[...]
$ git push
To https://git.company.com/repo.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://git.company.com/repo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g. 'git pull ...')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
@jnareb
jnareb / .console
Created July 12, 2017 16:54
Przykładowy wynik wykonania operacji `git push`.
$ git push
Counting objects: 48, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (6/6), 1469 bytes | 0 bytes/s, done.
Total 48 (delta 0), reused 0 (delta 0)
To https://git.company.com/repo.git
f30abad..3fb00bd master -> master
export PROMPT_COMMAND='if [ "$(id -u)" -ne 0 ]; then echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history 1)" >> ~/.logs/bash-history-$(date "+%Y-%m-%d").log; fi'