Skip to content

Instantly share code, notes, and snippets.

@AlexandrFadeev
AlexandrFadeev / FizzBuzz.js
Created September 11, 2017 10:23
FizzBuzz JavaScript algorithm
function calculateFizzBuzz(num) {
for ( var i = 0; i < num.length; i++) {
if (i % 15 == 0) {
console.log(i + " FizzBuzz");
} else if (i % 3 == 0) {
console.log(i + " Fizz");
} else if (i % 5 == 0) {
console.log(i + " Buzz");
}
}
@AlexandrFadeev
AlexandrFadeev / pangramma.js
Created September 11, 2017 14:39
pagramma algorithm in javascript
function isPangramma(string) {
/**
define constant that hold alphabet count. We take in considiration that the alphabet is 'english'.8
*/
const alphabetCount = 26;
/**
Create new string that trims whitespaces from passed to function string as a parameter
*/
@AlexandrFadeev
AlexandrFadeev / palindrome.js
Last active September 11, 2017 18:57
Palindrome algorithm in javascript
/**
Palindrome algorithm.
Palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward,
such as 'madam' or 'racecar'.
*/
function isPalindrome(string) {
/**
initialize variable that holds reversed passed string and make this string lowercese
*/
@AlexandrFadeev
AlexandrFadeev / flattenArray.js
Last active September 12, 2017 05:10
Flatten array algorithm in javascript
/**
Convert nested array to flat array
*/
function flattenArray(arr) {
/**
Create en empty array. In this array we will push elements from nested array passed
as a parameter.
*/
var flatArray = [];
@AlexandrFadeev
AlexandrFadeev / binary search.js
Created September 12, 2017 12:13
Binary search algorithm in javascript
/**
Binary search algorithm
*/
// -------------------------------------------------------------------------------------------------
/**
Helper function that generates array of numbers from 0 to (n) elements
*/
@AlexandrFadeev
AlexandrFadeev / rename.sh
Created October 11, 2017 10:31
Rename local and remote branches
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@AlexandrFadeev
AlexandrFadeev / bytesToMega.swift
Created October 15, 2017 19:54
Covert bytes to megabytes in swift
let bcf = ByteCountFormatter()
bcf.allowedUnits = [.useMB] // optional: restricts the units to MB only
bcf.countStyle = .file
let string = bcf.string(fromByteCount: Int64(data.count))
print("formatted result: \(string)")
@AlexandrFadeev
AlexandrFadeev / shouldChangeCharacters.swift
Last active November 22, 2017 10:07
snippet for UITextFieldDelegate textField shouldChangeChaactersInRange...
func textField(textField: UITextField!, shouldChangeCharactersInRange range: NSRange, replacementString string: String!) -> Bool {
if let text = textField.text as NSString? {
let txtAfterUpdate = text.replacingCharacters(in: range, with: string)
self.callMyMethod(txtAfterUpdate)
}
return true
}
private func setupFormValidator() {
formValidator.rules.minValue = 1
formValidator.rules.maxValue = 2000
formValidator.addValidationTo(
view: receiverTextField, type: .require, fieldType: .none, errorMessage: "EmptyFormFieldError".localized,
errorMessageTitle: formTitleLabel.text)
if transferType == .receive || transferType == .refund {
formValidator.addValidationTo(
@AlexandrFadeev
AlexandrFadeev / .gitconfig
Created December 26, 2018 10:10
Find parent branch
[alias]
parent = "!git show-branch | grep '*' | grep -v \"$(git rev-parse --abbrev-ref HEAD)\" | head -n1 | sed 's/.*\\[\\(.*\\)\\].*/\\1/' | sed 's/[\\^~].*//' #"