Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jonbodner's full-sized avatar

Jon Bodner jonbodner

  • @jonbodner@noc.social
View GitHub Profile
public class CalcControllerTest {
@Test
public void result() {
CalcController c = new CalcController(new Calculator() {
@Override
public double process(String expression) {
if (expression.equals("1 + 1")) {
return 2;
}
package com.example.demo;
import com.example.demo.calculator.Calculator;
import com.example.demo.calculator.CalculatorImpl;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class DemoApplication {
package com.example.demo.controller;
import com.example.demo.calculator.Calculator;
import com.example.demo.calculator.CalculatorException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class CalcController {
package com.example.demo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoApplicationTests {
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
package com.example.demo.calculator;
import java.util.ArrayDeque;
import java.util.Deque;
public class CalculatorImpl implements Calculator {
public CalculatorImpl() {
}
@Override
package com.example.demo.calculator;
public interface Calculator {
double process(String expression);
}
@jonbodner
jonbodner / silly_fizzbuzz.go
Created September 14, 2018 02:10
FizzBuzz without if statements
package main
import (
"fmt"
"strconv"
)
func main() {
vals := [][]string{{"FizzBuzz", "Fizz"}, {"Buzz", ""}}
for i := 1; i <= 100; i++ {
type WorkPool struct {
work chan Runnable
shutdown chan struct{}
o sync.Once
}
type Runnable func()
func NewWorkPool(tasks int) *WorkPool {
work := make(chan Runnable, tasks)
func AddSlowly(a, b int) int {
time.Sleep(100 * time.Millisecond)
return a + b
}
func main() {
ch, err := Cacher(AddSlowly, 2*time.Second)
if err != nil {
panic(err)
}