Skip to content

Instantly share code, notes, and snippets.

const Chart = () => {
return (
<ResponsiveContainer>
<Chart data={data}>
<XAxis />
<YAxis />
<CartesianGrid />
<Line isAnimationActive={false} dataKey="y">
<LabelList dataKey="note" position="top" />
</Line>
const saveStuffToBackend = stuff => {
saveToBackend(stuff);
}
const genRowPartial = (foo) => (bar) => {
const [baz, setBaz] = useState(0);
return (
<tr><td><input value={baz} onChange={e => setBaz(e.target.value)} onBlur={() => saveStuffToBackend(baz)} /></td></tr>
);
class Blah {
foo: null,
someModel: null,
constructor(args) {
someModel = args.someModel;
foo = new Foo({
"fn": a
});
@JamesZoft
JamesZoft / SeleniumScreenshotUploader.java
Last active April 11, 2019 09:08
Uploads screenshots to a specified S3 bucket.
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
import org.slf4j.Logger;
@JamesZoft
JamesZoft / MyTest.java
Created April 3, 2019 16:47
Injecting a Jupiter extension into a JUnit test
class MyTest {
//...
private WebDriver driver;
@RegisterExtension
TakeScreenshotOnFailureExtension takeScreenshotOnFailureExtension = new TakeScreenshotOnFailureExtension(driver);
//...
}
@JamesZoft
JamesZoft / TakeScreenshotOnFailureExtension.java
Last active April 5, 2019 20:39
Implementation of TestExecutionExceptionHandler that takes a screenshot of the current selenium context to be used as a Jupiter extension
import com.amazonaws.SdkClientException;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class Reminder < ApplicationRecord
attr_accessor :reminder_text, :reminder_date
end
<T> T waitUntil(Function<? super WebDriver, T> condition, int timeout, int pollingEvery, Class<? extends Throwable>... exceptions) {
Wait<WebDriver> wait = new FluentWait<>(driver)
.withTimeout(timeout, SECONDS)
.pollingEvery(pollingEvery, MILLISECONDS)
.ignoreAll(Arrays.asList(exceptions));
return wait.until(condition);
}
List<Container> containers = session.createNativeQuery("select * from containers c", Container.class)
.list();
containers.forEach(container -> {
SubEntity subEntity = session.createNativeQuery("select * from subEntity se join containers c on se.id = c.fk_se where c.id = :id")
.setParameter("id", container.getId())
.uniqueResult();
container.setSubEntity(subEntity);
});
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
diceType: 6,
diceNumber: 2,
};
}
render() {