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
impl Solution { | |
pub fn is_palindrome(x: i32) -> bool { | |
if x < 0 { | |
return false; | |
} | |
let mut x_copy = x; | |
let mut reverse: i32 = 0; | |
while x_copy > 0 { | |
reverse = (reverse * 10) + (x_copy % 10); |
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
use std::str::FromStr; | |
use regex::Regex; | |
const ADDITION: &str = "(\\d+)\\s*?(\\+)\\s*?(\\d+)"; | |
const SUBTRACTION: &str = "(\\d+)\\s*?(\\-)\\s*?(\\d+)"; | |
const MULTIPLICATION: &str = "(\\d+)\\s*?(\\*)\\s*?(\\d+)"; | |
const DIVISION: &str = "(\\d+)\\s*?(/)\\s*?(\\d+)"; | |
fn main() { |
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
module CalculatorStrategy | |
def calculate(number_a, number_b) | |
raise "Not implemented" | |
end | |
end | |
class AdditionStrategy | |
include CalculatorStrategy | |
def calculate(number_a, number_b) |
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 strictEquals(a, b) { | |
// If one is NaN, we'll always receive false anyway | |
if (Object.is(a, NaN)) { | |
return false; | |
} | |
// -0 and 0 special case | |
if ((Object.is(a, 0) && Object.is(b, -0)) || (Object.is(a, -0) && Object.is(b, 0))) { | |
return true; | |
} |
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
// Let's create a class to build a simple Pizza | |
// Our PizzaBuilder can set: | |
// 1. Pizza size (required) | |
// 2. Pizza flavour (required) | |
// 3. Pizza crust (optional) | |
// We must make sure that the "cook" function is type-checked and can be called | |
// only if we have set a size or a flavour. | |
type PizzaSizes = 'small' | 'medium' | 'large' | 'extra large'; | |
type PizzaFlavour = 'pepperoni' | 'bbq chicken' | 'margherita' | 'vegetarian'; |
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
class FakeResource(): | |
def Bucket(self, bucket): | |
return self | |
def put_object(self, Key=None, Body=None, ACL='', Expires='', ContentType=''): | |
# We do nothing here, but return the same data type without data | |
return {} | |
class FakeSession(Session): | |
def resource(self, name): |
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 mock | |
from django.core import mail | |
from django.test import TestCase | |
from boto3.session import Session | |
from reports.models.report import Report | |
class FakeResource(): | |
def Bucket(self, bucket): | |
return 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 django.core import mail | |
from django.test import TestCase | |
from reports.models.report import Report | |
class ReportTest(TestCase): | |
def tearDown(self): | |
Report.objects.all().delete() | |
mail.outbox = [] | |
def test_create_report_and_send_by_email(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
import StringIO | |
from django.db import models | |
from boto3.session import Session | |
class Report(models.Model): | |
# ... | |
# Information about the model | |
def create_report_and_send_by_email(self): |