Skip to main content

Posts

Showing posts from 2019

realtime data with GraphQL subscriptions / apollo-server

using Apollo server:




1. server.js


const { ApolloServer, gql, AuthenticationError, PubSub } = require('apollo-server')
constpubsub = newPubSub()

constserver = newApolloServer({ typeDefs, resolvers, formatError:error=> { console.log(JSON.stringify(error)) return { ...error } },
introspection:true, playground:true, context:async ({ req, connection }) => { if (connection) { return { pubsub } }
if (req) { constme = awaitgetMe(req)
return { me, secret:process.env.SECRET, pubsub } } } })

2. schema: project.js

extend type Subscription { projectAdded: Project } 3. resolver: project.js

constPROJECT_CHANNEL = 'PROJECT_CHANNEL' Mutation: { addProject:combineResolvers( isAuthenticated, async (parent, { projectInput }, { models, me, pubsub }) => { const { projectName, clientId } = projectInput constproject = awaitProject.create({ accountId:me.accountId, projectName:projectName || 'default project', clientId:clientId || 0 })
console.log(me.accountId) if (me.accountId === 'sat') pubsu…

Barcode in OCCopier app - use QRCode to speed up data entry

import { BarCodeScanner } from'expo-barcode-scanner'


QRCode:
generate QR code: https://www.the-qrcode-generator.com/

Integrate Barcode into React Native mobile app

On OC Copier mobile app, we have integrated QR Code into Contact Form, so contact info will automatically fill in when barcode is being scanned.

To generate QR Code, we are using
https://www.the-qrcode-generator.com

Expo
BarCodeScannerhttps://docs.expo.io/versions/latest/sdk/bar-code-scanner/



* feature: SendGrid provides service to send email notification
https://sendgrid.com/

see pricing:
Free Try it out! Send 40,000 emails for 30 days, then 100/day forever.

Upload file for React Native + Rest API

Using fetch:

constuploadResponse = awaituploadPhotoAsync(uris[0], newFileName.concat(ext)) constuploadResult = awaituploadResponse.text()
letformData = newFormData() formData.append('file', { uri:localUri, name:filename, type })
consturl = `${UPLOAD_PHOTO_TOANDMAP_URL}${newFileName}` returnawaitfetch(url, { method:'POST', body:formData, header: { 'content-type':'multipart/form-data' } })

Upload Files With GraphQL, Apollo, and React-Native

React-Native: we need extra component: RNFetchBlob
With React-Native, it’s a little bit more complicated. It boils down to intercepting the outgoing request and changing it to be a multi-part form and injecting the file blob. To trigger the action, you can include a special flag in your mutation that tells the code to treat the variable “file” as a file to upload.

use Quokka in Visual Studio code

To install Quokka:
https://quokkajs.com/docs/

Once the extension is installed, press Ctrl/Cmd + Shift + P to display the editor’s command palette:

exportconstarrayToObjectWithValue = array=> array.reduce((obj, item) => { obj[item.name] = item.value returnobj }, {})
exportconstobjectToArray = obj=> Object.keys(obj).map(key=> { return { name:key, value:obj[key] } })
constarr = [{ name:'test', value:123 }, { name:'test1', value:12 }] constobj = arrayToObjectWithValue(arr) console.log(obj)
constobj2 = { test:123, test1:222 } constarr2 = objectToArray(obj2) console.log(arr2)
screen shot:

The Trip to the Pacific Garbage Patch

(My name is M&M) I was thrown into a garbage can after I was used from The Mystical Smoothie Palace.
The wind was blowing and the garbage can was filled past the top, so I got blown off. I started rolling away towards the ocean. On my way to the ocean it was very rough because while I was rolling with the wind about 1 million people stepped on me (It was actually 20 people). I was flattened badly, but luckily I couldn’t feel a thing. A seagull tried to eat me but thought I didn’t taste good enough (thankfully). The wind kept blowing me until… I saw the sea for the first time!!! I’ve only heard tales about it from my old buddies,
but this is better than I ever imagined!!! I can’t wait to get in!!! The wind blew me faster than ever, until I wasn’t rolling anymore, I was flying over the ocean!!! I’m in the ocean!!! The fresh smell!!! I was floating deeper in the ocean as I heard the waves roar faint away. Soon, I couldn’t see the shore, but I still heard voices. I turned around and sa…
3 kids: 2 pre-teens and one teenager.  I am going to use this blog to record my own foot prints in this journey of growth with our three kids as they themselves grow into young adults. 
I will try to share our own experiences in helping them with their academic and extracuuricular endeavors. The goal is to provide some of our insights and hopefully encourage other parents to share their experiences and insights.

Vocabulary Victory - Build vocabulary at your own pace

download links:

iOS:
https://apps.apple.com/us/app/vocabulary-victory/id1485320131 Android:
https://play.google.com/store/apps/details?id=com.andmap.vocabularyvictory


update:
1. max connection error on mysql, when do the subquery cards in the loop of query of project, move this function to front end => load flashCards: []  from dashboard.js to project-in-row.js
flashCards:async (project, args, { models }) => { /*const cards = await FlashCard.findAll({ where: { projectId: project.id } }) return cards */ return [] } https://www.qr-code-generator.com/

Random Information

Boom!!! "What was that," asked Tina frightenedly. ", Oh, never mind that was my tummy." I thought I could trust you in every way but looks like I was wrong (No one said that, just a thought...). So when I went to New York City, there were chocolate covered balloons everywhere. I tried to eat one but found out the chocolate were a century old. I always wanted to fly, and I did!!! But I randomly flew into everything. I was in kind of in a mess, but never fear, Emily Wang is here!!! She flew out of nowhere and pulled out her very awesome, spectacular, and legendary vacuum cleaner. Also bringing out her…(very awesome, spectacular, and legendary) DUST CLEANER!!!

Find out what happens next on episode 2.

We are Farmers, bum ba dum bum bum bum bum!!!  Don't wait, call 8  "800 888 8888"