Skip to content

Instantly share code, notes, and snippets.

View yasarix's full-sized avatar

Yaşar Şentürk yasarix

View GitHub Profile
@yasarix
yasarix / pyqt_listtree_datamodel.py
Created October 28, 2012 09:15
Using Data Model with ListTree in PyQT
''' Creating Model '''
my_model = QtGui.QStandardItemModel(0, 7)
''' Setting headers/column names '''
my_model.setHeaderData(0, QtCore.Qt.Horizontal, QtCore.QVariant("Column 1"))
my_model.setHeaderData(1, QtCore.Qt.Horizontal, QtCore.QVariant("Column 2"))
my_model.setHeaderData(2, QtCore.Qt.Horizontal, QtCore.QVariant("Column 3"))
myListTree.setModel(my_model)
@yasarix
yasarix / pyqt_listtree_group.py
Created October 28, 2012 09:22
Creating groups in ListTree widges in PyQt
parent_item = my_model.invisibleRootItem()
root_item = QtGui.QStandardItem(QtCore.QString("Group 1"))
parent_item.appendRow(root_item)
parent_item = root_item
parent_item.appendRow(
[
QtGui.QStandardItem(QtCore.QString("Data 1"))),
QtGui.QStandardItem(QtCore.QString("Data 2"))),
QtGui.QStandardItem(QtCore.QString("Data 3")))
@yasarix
yasarix / sqlite_table_structure.py
Created October 28, 2012 09:47
Getting SQLite table structure
def getTableStructure(self, table_name):
"""Returns table structure"""
query = "PRAGMA table_info('" + table_name +"')"
try:
result = cursor.execute(query)
fields = result.fetchall()
return fields
except sqlite3.Error, e:
@yasarix
yasarix / check_file_exist.sh
Created January 25, 2013 01:05
Check if file exists
#!/bin/bash
if [ ! -f /tmp/foo.txt ]
then
echo the file does not exist
fi
@yasarix
yasarix / android_check_unknown_sources.java
Created November 14, 2014 00:58
Android Check Unknown Sources
try {
isNonPlayAppAllowed = Settings.Secure.getInt(context.getContentResolver(), Settings.System.INSTALL_NON_MARKET_APPS) == 1;
Log.d(TAG, "Unknown sources check: "+ Boolean.toString(isNonPlayAppAllowed));
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
@yasarix
yasarix / time-duration-json.go
Created March 27, 2016 04:16
time.Duration to JSON
package main
import (
"encoding/json"
"fmt"
"strings"
"time"
)
type Duration struct {
@yasarix
yasarix / dashboard.go
Created June 7, 2016 00:04
termui Dashboard sample
package main
import (
ui "github.com/gizak/termui"
"log"
"sync"
"time"
)
type UiElements struct {
#!/bin/bash
if [ -n "$CI_BUILD_REF_NAME" ]; then
branch_name=$CI_BUILD_REF_NAME
else
branch_name=$(git symbolic-ref -q HEAD)
branch_name=${branch_name##refs/heads/}
branch_name=${branch_name:-HEAD}
fi
package main
import (
"reflect"
)
// StructCopy Copies the common field values from source to target. Pass the pointers of the interfaces
func StructCopy(source interface{}, target interface{}) {
sourceElem := reflect.ValueOf(source).Elem()
targetElem := reflect.ValueOf(target).Elem()
git diff --no-prefix [<other git-diff arguments>]