This file contains hidden or 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 string | |
def is_word(match): | |
for word in open('/usr/share/dict/words', 'r'): | |
if str(word.strip().lower()) == str(match.lower()): | |
return True | |
return False |
This file contains hidden or 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
// Add employee.badge_number to matching person in another database collection | |
db.getSiblingDB('databaseA').getCollection('employees').find({}).forEach(function(employee1) { | |
db.getSiblingDB('databaseB').getCollection('people').update( | |
{"_id": employee1._id}, | |
{ | |
"$set": { | |
"badge_number": employee1.badge_number | |
} | |
} | |
) |
This file contains hidden or 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 fire | |
import requests | |
from bs4 import BeautifulSoup | |
# Web scrape example using python and BeautifulSoup | |
# Setup: pip install requests beautifulsoup4 fire | |
# Run: python webscrape.py scrape | |
class WebScrape(object): | |
url = "https://www.themuse.com/advice/43-simple-habits-thatll-improve-your-life-even-if-you-just-pick-one" |
This file contains hidden or 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 org.hibernate.validator.constraints.NotEmpty; | |
import org.junit.BeforeClass; | |
import org.junit.Test; | |
import javax.validation.ConstraintViolation; | |
import javax.validation.Validation; | |
import javax.validation.Validator; | |
import javax.validation.ValidatorFactory; | |
import java.util.Set; |
This file contains hidden or 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.prototype.method = function (name, func) { | |
this.prototype[name] = func; | |
return this; | |
}; | |
String.method('trim', function ( ) { | |
return this.replace(/^\s+|\s+$/g, ''); | |
}); | |
document.writeln('"' + " neat ".trim( ) + '"'); |
This file contains hidden or 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.prototype.method = function (name, func) { | |
this.prototype[name] = func; | |
return this; | |
}; | |
Number.method('integer', function ( ) { | |
return Math[this < 0 ? 'ceil' : 'floor'](this); | |
}); | |
document.writeln((-10 / 3).integer( )); // −3 |
This file contains hidden or 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 java.util.Arrays; | |
import java.util.Random; | |
import java.util.function.Predicate; | |
public class BubbleSort { | |
private static Random random = new Random(); | |
private Integer[] sort(Integer[] array, Predicate<Integer> sortType) { | |
int count = 0; |
This file contains hidden or 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 java.util.List; | |
import java.util.Random; | |
import java.util.function.Supplier; | |
import java.util.stream.Collectors; | |
import java.util.stream.Stream; | |
class TestRandomStringGenerator { | |
private static Supplier<String> randomDischargeId = () -> RandomStringUtils.randomConsonant(8); | |
public static void main(String[] args) { |
This file contains hidden or 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 rx import Observable, Observer | |
Observable.interval(1000) \ | |
.map(lambda i: "{0} Mississippi".format(i))\ | |
.subscribe(lambda s: print(s)) | |
input("Press any key to quit") |
This file contains hidden or 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 rx import Observable, Observer | |
letters = Observable.from_(['Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon']) \ | |
.map(lambda s: len(s)) \ | |
.filter(lambda i: i >= 5) \ | |
.subscribe(lambda i: print(i)) |