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
/* fn main() { | |
// test array to make sure things work right | |
let numbers = [5, 5, 5, 2, 1]; | |
/* use newly created method to do a count elements match a predicate. | |
Due to elements being borrowed once for the predicate and again for underlying running, parameter in closure must be dereferenced twice. */ | |
println!("{}", numbers.iter().count_where(|n| **n == 1)); |
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
import Foundation | |
// create extension of the Int type | |
extension Int { | |
// computed property that grab factors found in number | |
var factors: [Int] { | |
// cause property to fail if number is 0. | |
guard self != 0 else { preconditionFailure("0 has infinite factors.") } | |
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
import Foundation | |
extension String { | |
// function that can easily perfom regex and grab groups | |
func matching(regexPattern: String) -> [[String]]? { | |
// attempt to create an NSRegular expression object | |
guard let regex = try? NSRegularExpression(pattern: regexPattern) else { return nil } | |
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
import Foundation | |
// digits will retrieve the digits in a number | |
func digits(inNumber number: Int) -> [Int] { | |
return String(number).compactMap { $0.wholeNumberValue } | |
} | |
// product of digits will iterate over every digit in a number and multiply them together | |
func productOfDigits(_ number: Int) -> Int { | |
return digits(inNumber: number).reduce(1) { $0*$1 } |
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
import Foundation | |
// the following extensions allow the easy retrieval of euler's number as a float or Double, just like pi | |
extension Double { | |
// create type constant and set it to the value of e, by passing 1 as an argument to exp function, which is equivalent to e^1. | |
static let e: Double = exp(1.0) | |
} | |
extension Float { |
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
import Foundation // import Foundation, so that pow function can be used | |
// powTower function takes a number and return the result of a tower with the specified number of copies | |
func powTower(number: Double, withCopies: Int) -> Double { | |
var result: Double = number // variable to hold results, with an initial value being the same as the number specified | |
if (withCopies == 1) { | |
return number | |
} else if (withCopies > 1) { | |
// create a loop that will repeat for less than specified number of copies, so that math is accurate |
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 script requies the python module wifi_qrcode_generator and is written for Python version 2.7. | |
# instructions to get module can be found at https://github.com/lakhanmankani/wifi_qrcode_generator | |
import wifi_qrcode_generator | |
name = raw_input("filename: ") # holds name of file, so there can be some measure of security | |
ssid = raw_input("SSID: ") # holds network name | |
while True: | |
hidden = bool(raw_input("SSID is hidden (press enter if not hidden): ")) # variable hold boolean for if network is hidden |
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
<?php | |
class YouTubeHabari extends Plugin | |
{ | |
private $output; | |
// the following function will make youtube shortcode work | |
function filter_shortcode_youtube($content, $code, $attrs, $context) | |
{ | |
// the following assigns embed code to variable and embeds video specfied by user and at specified dimensions | |
$this->output = '<iframe width="' . $attrs['width'] . '" height="' . $attrs['height'] . '" src="http://youtube.com/embed/' . $attrs['video'] . '" frameborder="0" allowfullscreen></iframe>'; |