Skip to content

Instantly share code, notes, and snippets.

View andrey-str's full-sized avatar

Andrey Streltsov andrey-str

View GitHub Profile
@andrey-str
andrey-str / lldb_qt.py
Last active August 29, 2015 14:23 — forked from wmanth/lldb_qt.py
import lldb
def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand('type summary add QString -F lldb_qt.QString_summary')
debugger.HandleCommand('type summary add QUuid -F lldb_qt.QUuid_summary')
print 'lldb_qt.py has been loaded and is ready for use.'
def QString_summary(value, internal_dict):
name = value.GetName()
deref = '->' if value.TypeIsPointerType() else '.'
@andrey-str
andrey-str / datediff.mm
Last active August 29, 2015 14:28
Absolute time to relative time(e.g. 2 days ago)
QString dateDiff(const QString&origDate) {



NSDateFormatter* df = [$CE dateFormatter]; 

NSDate *convertedDate = [df dateFromString:origDate.toNSString()]; 


NSDate *todayDate = [NSDate date]; 

double ti = [convertedDate timeIntervalSinceDate:todayDate]; 

ti = ti * -1; 

@andrey-str
andrey-str / setElidedText.cpp
Last active July 9, 2021 05:00
Set "Elided....Text" to QLabel
void setElidedText(QLabel* label, const QString &text){
QFontMetrics metrix(label->font());
int width = label->width() - 2;
QString clippedText = metrix.elidedText(text, Qt::ElideMiddle, width);
label->setText(clippedText);
}
@andrey-str
andrey-str / ufw plexmediaserver app profile.md
Last active December 18, 2020 22:57
Plex Media Server UFW rule
[plexmediaserver]
title=Plex Media Server
description=The Plex Media Server is smart software that makes playing Movies, TV Shows and other media on your computer simple
ports=32400/tcp|1900/udp|32469/udp|5353/udp

Once you have defined your application file, put it in /etc/ufw/applications.d, then tell ufw to reload the application definitions with

ufw app update plexmediaserver
ufw app info plexmediaserver
@andrey-str
andrey-str / PDFDocument.cpp
Created October 12, 2015 23:15
Load and render a page from PDF with QuartzCore
#import "PDFDocument.h"
bool PDFDocument::loadDocument(const char *filename){
CFStringRef path;
CFURLRef url;
CGPDFDocumentRef document;
size_t count;
@andrey-str
andrey-str / common-utils.cpp
Created October 19, 2015 08:49
Reveal file in Finder or Explorer with Qt
void revealFile(QWidget* parent, const QString &pathToReveal) {
// See http://stackoverflow.com/questions/3490336/how-to-reveal-in-finder-or-show-in-explorer-with-qt
// for details
// Mac, Windows support folder or file.
#if defined(Q_OS_WIN)
const QString explorer = Environment::systemEnvironment().searchInPath(QLatin1String("explorer.exe"));
if (explorer.isEmpty()) {
QMessageBox::warning(parent,
@andrey-str
andrey-str / NSDictionary+XXXConvertValues.h
Created November 12, 2015 08:59 — forked from kristopherjohnson/NSDictionary+XXXConvertValues.h
Category on NSDictionary that will convert string values to numbers or vice versa. Useful for JSON deserialization.
#import <Foundation/Foundation.h>
@interface NSDictionary (XXXConvertValues)
// Return value associated wth key, converted to NSString
- (NSString *) stringValueForKey:(id)key;
// Return integer value associated with key, converted to integer
- (NSInteger) integerValueForKey:(id)key;
@andrey-str
andrey-str / UIImageView+CoordinateTransform.h
Last active May 5, 2018 12:36
Convert UIImageView coordintate to UIImage pixel coordinate and back turn around. Borrowed from here: http://b2cloud.com.au/tutorial/uiimageview-transforming-touch-coordinates-to-pixel-coordinates/
//
// Created by Andrey Streltsov on 16/11/15.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface UIImageView (CoordinateTransform)
-(CGPoint) pixelPointFromViewPoint:(CGPoint)viewPoint;
-(CGPoint) viewPointFromPixelPoint:(CGPoint)pixelPoint;
@andrey-str
andrey-str / bash_shortcut.sh
Last active November 19, 2015 14:03
Useful aliases for bash .profile
# common alaises
# up one level
alias ..="cd .."
# unload cacher applications preferences on Yosemite and up(maybe on Maverick too)
alias fixpref='killall -u andrey cfprefsd'
# refresh locate database
alias updatedb=open_in_appcode
# detailed directory listing
alias ll="ls -l"
@andrey-str
andrey-str / fix_bluetooth.sh
Created December 5, 2015 08:58
Fix bluetooth problem on Yosemite
#!/bin/sh
# Credits to author of this message(timgws): https://discussions.apple.com/thread/6693749?start=15&tstart=0
function msg() {
foo=$2
what="$(tr '[:lower:]' '[:upper:]' <<< ${foo:0:1})${foo:1}"
echo ">> ${what}ing $1...";
}
function __blued() {