Skip to content

Instantly share code, notes, and snippets.

const scrollToLocation = () => {
const scrolledRef = React.useRef(false);
const { hash } = useLocation();
React.useEffect(() => {
if (hash && !scrolledRef.current) {
const id = hash.replace('#', '');
const element = document.getElementById(id);
if (element) {
element.scrollIntoView({ behavior: 'smooth' });
scrolledRef.current = true;
import React from 'react';
import { render } from '@testing-library/react';
import App from './App';
import MyComponent from './MyComponent';
const MockMyComponent = () => {
React.useEffect(() => {
console.log('using an effect');
});
return (<div>Hello World</div>);
import React from 'react';
import { render } from '@testing-library/react';
import App from './App';
jest.mock('./MyComponent', () => () => {
React.useEffect(() => {
console.log('using an effect');
});
return (<div>Hello World</div>);
});
import React from 'react';
const MyMockComponent = () => (<div>Hello World</div>);
export default MyMockComponent;
@ericdcobb
ericdcobb / App.js
Last active February 12, 2020 23:10
import React from "react";
import "./styles.css";
import MyComponent from "./MyComponent";
export default function App() {
return (
<div className="App">
<MyComponent />
</div>
);
SlackAPI slackAPI = SlackAPIFactory.newSlackFactory()
.setClientId("test-id")
.setClientSecret("test-secret")
.build();
@POST
@Path("/events")
@Timed
public EventResponse eventResponse(Event event) {
if (!verificationToken.equals(event.getToken())) {
throw new ForbiddenException();
}
//Custom event processing here
}
@ericdcobb
ericdcobb / file_count.sh
Created October 20, 2016 20:55
Continuously Count open files for a supplied process, OSX
#!/bin/bash
echo "Counting files open by PID $1"
echo "Press [CTRL-C] to stop..."
while :
do
lsof -p $1 | wc -l
sleep 1
done
@ericdcobb
ericdcobb / package.json
Created May 21, 2015 02:57
simple node webserver that just prints all posted requests
{
"name": "basic-node-server",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
@SqlUpdate("INSERT INTO objects (list_of_integers) VALUES (:list_of_integers)")
@GetGeneratedKeys
int insert( @BindListIntegers("list_of_integers") List<Long> listOfIntergers);