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
// test/alphabet_position_test.rs | |
#[test] | |
fn it_should_ignore_non_characters() { | |
let replaced = alphabet_position("'a a. 2"); | |
assert_eq!(replaced, "1 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
// src/lib.rs | |
pub fn alphabet_position(s: &str) -> String { | |
s.to_lowercase() | |
.chars() | |
.filter(|x| x.is_alphabetic()) // <-- adding this line here | |
.map(|x| -> u8 { x as u8 - 'a' as u8 + 1 }) | |
.map(|x| -> String { x.to_string() }) | |
.collect::<Vec<String>>() | |
.join(" ") |
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
// test/alphabet_position_test.rs | |
#[test] | |
fn it_should_replace_the_sentence() { | |
let replaced = alphabet_position("The sunset sets at twelve o' clock."); | |
assert_eq!( | |
replaced, | |
"20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11" | |
); | |
} |
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
// test/alphabet_position_spec.rs | |
use dev_challenge_47::alphabet_position; | |
use speculate::speculate; | |
speculate! { // <-- it's a macro but who cares | |
describe "alphabet_position" { | |
it "should replace 'a' with 1" { | |
assert_eq!(alphabet_position("a"), "1"); | |
} | |
it "should replace 'A' with 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
#!/usr/bin/env python | |
import sys, yaml, json | |
try: | |
# included in standard lib from Python 2.7 | |
from collections import OrderedDict | |
except ImportError: | |
# try importing the backported drop-in replacement | |
# it's available on PyPI |
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
library io_testing; | |
import 'dart:async'; | |
import 'dart:io'; | |
import 'dart:convert'; | |
class UpperCaseConverter extends Converter<String, String> { | |
@override | |
String convert(String input) => input.toUpperCase(); |
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 ($) { | |
var cookieName = 'csrftoken'; | |
var xHeaderName = 'X-CSRFToken'; | |
var csrfSafeMethod = function (method) { | |
return /^(GET|HEAD|OPTIONS|TRACE)$/.test(method); | |
}; | |
var getCookie = function (cookie) { |
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
#!/bin/bash | |
set -e | |
cd /tmp | |
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-2.2.tar.gz | |
tar -xzf setuptools-2.2.tar.gz | |
cd setuptools-2.2 | |
sudo jython27 setup.py install --prefix=/opt/jython27 |
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
{% extends 'layouts/backend.html' %} | |
{% load i18n %} | |
{% block body %} | |
<div class="row"> | |
<div class="col-md-6"> | |
<form id="omni-form" action="{% url 'post_list' %}" method="GET" class="form-inline" role="form"> | |
<div class="input-group"> | |
<label class="sr-only" for="omnisearch">{% trans 'Search for posts' %}</label> | |
<input type="text" name="q" class="form-control" id="omnisearch" |
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
#!/usr/bin/python | |
import json, sys, urllib2 | |
url = sys.argv[1] | |
apiKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX' | |
data = { | |
'longUrl' : url | |
} | |
req = urllib2.Request('https://www.googleapis.com/urlshortener/v1/url?key='+apiKey) |