Skip to content

Instantly share code, notes, and snippets.

View darhonbek's full-sized avatar

Darkhonbek Mamataliev darhonbek

View GitHub Profile
@darhonbek
darhonbek / quickSort.cpp
Created October 23, 2017 18:17
Quick Sort
#include <iostream>
using namespace std;
int partition(int *, int, int);
void printArray(int *, int);
void quickSort(int *arr, int start, int end) {
if(start < end) {
int q = partition(arr, start, end);
quickSort(arr, start, q);
@darhonbek
darhonbek / bucketSort.cpp
Created October 24, 2017 01:37
BucketSort
#include <iostream>
using namespace std;
void print(int *arr, int n) {
for(register int i=0; i<n; i++) {
cout<<arr[i]<<" ";
}
}
void bucketSort(int *arr, int n) {
@darhonbek
darhonbek / radixSort.cpp
Created October 24, 2017 01:56
Radix Sort
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
void print(int *arr, int n) {
for(register int i=0; i<n; i++) {
cout<<arr[i]<<" ";
}
cout<<"\n";
@darhonbek
darhonbek / stringRadixSort.cpp
Last active October 24, 2017 09:21
String Radix sort. For strings containing only lowercase alphabet characters.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
template <class T>
void print(T *arr, int n) {
for(register int i=0; i<n; i++) {
cout<<arr[i]<<" ";
}
@darhonbek
darhonbek / README.md
Created December 21, 2017 01:14 — forked from hofmannsven/README.md
My simply Git Cheatsheet
@darhonbek
darhonbek / String+Indexation.swift
Last active June 1, 2020 02:16
String Indexation in Swift
extension StringProtocol {
subscript(_ offset: Int) -> Element {
return self[index(startIndex, offsetBy: offset)]
}
subscript(_ range: Range<Int>) -> SubSequence {
return prefix(range.lowerBound+range.count).suffix(range.count)
}
@darhonbek
darhonbek / Substring.swift
Created December 25, 2017 11:02
Check if a string contains a substring (Swift 4)
extension String {
func contains(find: String) -> Bool{
return self.range(of: find) != nil
}
func containsIgnoringCase(find: String) -> Bool{
return self.range(of: find, options: .caseInsensitive) != nil
}
}
var value = "Hello world"
@darhonbek
darhonbek / devnotes1.swift
Created January 15, 2018 14:17
DevNotes for iOS beginners: Changing button's label
// Wrong
if bgAudioPlayer.isPlaying {
bgAudioPlayer.stop()
pausePlayButton.titleLabel?.text = "Play"
} else {
bgAudioPlayer.play()
pausePlayButton.titleLabel?.text = "Pause"
}
// Right
@darhonbek
darhonbek / textField.swift
Created February 17, 2018 10:25
Ensure # of chars dose not exceed the limit (UITextField)
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let nsString = textField.text as NSString?
let newString = nsString?.replacingCharacters(in: range, with: string)
if let string = newString,
string.count > YOUR_LIMIT_HERE {
return false
}
return true
}
@darhonbek
darhonbek / CeasarCipher.swift
Last active October 5, 2018 06:46
Ceasar's Cipher Brute Force
// MARK: - Main
var cipherText = "VSRQJHEREVTXDUHSDQWU".lowercased()
let decipheredTexts = decipherText(cipherText)
for (k, s) in decipheredTexts {
print("Shifts: \(k)\t\(s)")
}
// MARK: - Actions