Skip to content

Instantly share code, notes, and snippets.

View barsumek's full-sized avatar

Bartosz Sumper barsumek

View GitHub Profile
object Sequences {
def filterPrimeCount(toFilter: Seq[Int], toCheckPrimeCount: Seq[Int]): Seq[Int] = {
def isPrime(num: Int): Boolean = {
require(num >= 0)
num match {
case n if n == 2 || n == 3 => true
case n if n < 2 || n % 2 == 0 => false
case _ => 5.to(math.sqrt(num).toInt, 2).forall(num % _ != 0)
}
import java.time.format.DateTimeFormatter
import java.time.{LocalDate, LocalTime}
import scala.annotation.tailrec
object Sessions {
private val DateTimeFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
private val MinSessions = 6
private case class SessionDateTime(date: LocalDate, time: LocalTime)
@barsumek
barsumek / PokemonScreen.js
Last active November 22, 2018 13:30
Detox your GraphQL: Pokemon Screen
class PokemonScreen extends Component {
render() {
const { loading, error, myPokemon } = this.props.data;
if (loading) {
return <ActivityIndicator />
}
if (error) {
return <ErrorScreen />
}
@barsumek
barsumek / PokemonScreen.spec.js
Created November 22, 2018 10:17
Detox your GraphQL: Pokemon Screen test
// /* eslint-env detox/detox, mocha */
describe("Test Pokemon screen", () => {
beforeEach(async () => {
await device.reloadReactNative();
});
it("Display MaxLvl if the pokemon has maximum level.", async () => {
await expect(element(by.id("pokemonButton"))).toBeVisible();
await element(by.id("pokemonButton")).tap();
await expect(element(by.text("Level: MaxLvl"))).toBeVisible();
@barsumek
barsumek / schemaExample.json
Last active November 22, 2018 10:44
Detox your GraphQL: Schema example
{
"__schema": {
"queryType": {
"name": "Query"
},
"mutationType": null,
"types": [
{
"kind": "OBJECT",
"name": "Query",
@barsumek
barsumek / schema.js
Created November 22, 2018 10:27
Detox your GraphQL: Schema types definitions
const { gql } = require("apollo-server-express");
const schemaString = gql`
scalar Date
enum PokemonType {
Normal
Fire
Water
Grass
@barsumek
barsumek / mockSchema.js
Last active November 22, 2018 10:54
Detox your GraphQL: Mock schema
const { ApolloServer } = require("apollo-server-express");
const { buildClientSchema } = require("graphql");
const { resolvers } = require("./schema");
const introspectedSchema = require("./schemaExample.json");
const PORT = 8089;
function createServerWithMockedSchema(customMocks = {}) {
const schema = buildClientSchema(introspectedSchema);
@barsumek
barsumek / startServerFunctions.js
Created November 22, 2018 10:59
Detox your GraphQL: Functions for starting the server
const express = require("express");
const PORT = 8089;
let graphQLServerApp;
let httpServer;
function startHttpServer() {
return new Promise(resolve => {
httpServer = graphQLServerApp.listen(PORT, () => {
function stopHttpServer() {
return new Promise(resolve => httpServer.close(() => resolve()));
}
async function stopGraphQLServer() {
if (!httpServer) {
console.warn("Tried to close null HTTP server.");
return;
}
@barsumek
barsumek / pokemonMock.js
Last active November 22, 2018 13:43
Detox your GraphQL: Mock the Pokemon's level
// Test non-max Pokemon level
{
const defaultPokemon = {
Pokemon: () => ({
level: 10
})
};
//...
await startGraphQLServer({ ...defaultPokemon });
}