Skip to content

Instantly share code, notes, and snippets.

Dave Ceddia dceddia

Block or report user

Report or block dceddia

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dceddia
dceddia / javascript.json
Created Oct 3, 2019
VSCode Snippets for React
View javascript.json
{
"Insert a function": {
"prefix": "f",
"body": [
"function $1($2) {\n $0\n}\n"
],
"description": "Insert a function"
},
"const arrow": {
"prefix": "c>",
@dceddia
dceddia / new-post.sh
Created Feb 1, 2019
Create a new post based in Gatsby. (make sure to create a new-post-template.md file)
View new-post.sh
#!/bin/bash
# Print usage if args are missing
if [ -z $1 ]; then
echo "Usage: new-post <slug>"
exit
fi
SLUG=$1
DAY=$(date +%Y-%m-%d)
@dceddia
dceddia / App.js
Created Jun 15, 2018
Asking for permission to use the camera.
View App.js
export default class App extends React.Component {
...
componentDidMount() {
Permissions.askAsync(Permissions.CAMERA)
.then(({ status }) =>
this.setState({
cameraPermission: status === 'granted'
})
);
@dceddia
dceddia / App.js
Created Jun 15, 2018
Take a picture after 30 seconds.
View App.js
const PHOTO_INTERVAL = 30000;
const FOCUS_TIME = 3000;
class Autoshoot extends React.Component {
componentDidMount() {
this.countdown = setTimeout(
this.takePicture,
PHOTO_INTERVAL
);
}
@dceddia
dceddia / server.js
Created Jun 15, 2018
Handle POST requests
View server.js
// Store the single image in memory.
let latestPhoto = null;
// Upload the latest photo for this session
app.post('/', (req, res) => {
// Very light error handling
if(!req.body) return res.sendStatus(400);
console.log('got photo')
@dceddia
dceddia / App.js
Created Jun 15, 2018
Adding a button to take the picture
View App.js
render() {
const { photo } = this.state;
return (
<Camera
style={{ flex: 1 }}
type={Camera.Constants.Type.back}
ref={cam => this.camera = cam}>
<TouchableOpacity
style={{ flex: 1 }}
@dceddia
dceddia / App.js
Created Jun 15, 2018
Upload pictures to the server
View App.js
uploadPicture = () => {
return fetch(SERVER_URL, {
body: JSON.stringify({
image: this.state.photo.base64
}),
headers: {
'content-type': 'application/json'
},
method: 'POST'
})
@dceddia
dceddia / server.js
Created Jun 15, 2018
Bare bones Express server
View server.js
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
// If your phone has a modern camera (unlike my iPhone 4S)
// you might wanna make this bigger.
app.use(bodyParser.json({ limit: '10mb' }));
// TODO: handle requests
@dceddia
dceddia / server.js
Created Jun 15, 2018
Handle GET requests
View server.js
// View latest image
app.get('/', (req, res) => {
// Does this session have an image yet?
if(!latestPhoto) {
return res.status(404).send("Nothing here yet");
}
console.log('sending photo');
try {
@dceddia
dceddia / App.js
Created Jun 15, 2018
Timers trigger more timers.
View App.js
takePicture = () => {
this.camera.takePictureAsync({
quality: 0.1,
base64: true,
exif: false
}).then(photo => {
this.setState({ photo });
// In 27 seconds, turn the camera back on
setTimeout(() => {
You can’t perform that action at this time.