This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// An C++ example to fill a 2D array diagonally, written by AhmetCanSolak | |
#include <bits/stdc++.h> | |
int main(void){ | |
// Fill this array with the 1D array you want to reshape, current values are just for testing! | |
std::vector<int> my_one_dimensional_array={1,2,3,4,5,6,7,8,9,10}; | |
//Calculate the required size for 2D result | |
int z =1; | |
while( ( ((z) * ((z)+1))/2 ) < my_one_dimensional_array.size()){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function to flatten dictionary | |
def flattenDict(dictionary): | |
results={} | |
for key,value in dictionary.items(): | |
if isinstance(value,dict): | |
tempDict = flattenDict(value) | |
for subkey,subvalue in tempDict.items(): | |
results[key+"."+subkey]=subvalue | |
else: | |
results[key]=value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T> | |
class disjointset | |
{ | |
public: | |
disjointset(int n) { | |
size = n; | |
arr.reserve(n); | |
rank.reserve(n); | |
makeSet(); | |
setcount = n; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for problem text https://www.hackerrank.com/challenges/kundu-and-tree/problem | |
#include <bits/stdc++.h> | |
typedef long long int LT; // suitable long type | |
using namespace std; | |
template<typename T> | |
class disjointset | |
{ | |
public: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
'CreateEvent': 183775, | |
'IssueCommentEvent': 99271, | |
'WatchEvent': 107234, | |
'PullRequestReviewCommentEvent': 27644, | |
'PushEvent': 761788, | |
'PullRequestEvent': 84235, | |
'CommitCommentEvent': 2770, | |
'MemberEvent': 5369, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This is a simple demonstration of observer pattern | |
""" | |
__author__ = 'AhmetCanSolak' | |
class Subject(object): | |
observers = [] | |
def __init__(self): | |
self.observers = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pprint import pprint | |
# CamelCase because it "acts" like a class | |
def CounterController(): | |
class CounterControllerPrivate(object): | |
def __init__(self): | |
self.counter = 0 | |
def add_one(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
# ------ Pythonic solution | |
def alternative_solution(inp): | |
cntr = Counter([inp[i:i+2] for i in range(len(inp)-1)]) | |
maxc = cntr.most_common(1)[0][1] | |
return [key for key,elem in cntr.items() if(elem==maxc)] | |
# ------- Given Solution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""This gist created to demonstrate an layout error, however, problem is solved with switching to anaconda/python | |
""" | |
import sys | |
from PyQt5.QtCore import Qt | |
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QSlider, QScrollArea, QFrame, QPushButton | |
from PyQt5.QtWidgets import QVBoxLayout, QHBoxLayout | |
from vispy.scene import SceneCanvas, PanZoomCamera | |
class Left(QHBoxLayout): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Windows" : { | |
"0.0.1": "121aIVQEUjwVEZWX3OiTu17AesRDgC494", | |
"0.0.2": "1CECPG7WD9P9A1_ZSZFpc58SvfLx55UdR", | |
"0.0.3": "1Z4VYH9qSP-9mw1yX9u-W7tgAETBfathv", | |
"0.0.4": "14m0ShfQMPaCOuZOQ-PsLYQLXIcsUA5Fd", | |
"0.0.5": "1fWzHWfGp_5fprsrgI6my8I-Vjo1GKg-Z" | |
}, | |
"Darwin": { | |
"0.0.1": "1l7fWJG5TO5tWCOAsKdM1k1kHdv0VSVem", |