Skip to content

Instantly share code, notes, and snippets.

View nixjs's full-sized avatar
:octocat:
Thanks for visiting

Nghi Nguyen nixjs

:octocat:
Thanks for visiting
View GitHub Profile
@nixjs
nixjs / graphql.config.js
Last active December 23, 2019 02:15
Config instance ApolloClient
import { HttpLink } from "apollo-link-http";
import { InMemoryCache } from "apollo-cache-inmemory";
import apolloLogger from "apollo-link-logger";
import { from } from "apollo-link";
import { ApolloClient } from "apollo-client";
const httpLink = new HttpLink({
uri: "https://api.graph.cool/simple/v1/ck3h4yebx07690132c670msn3"
});
@nixjs
nixjs / index.js
Last active December 23, 2019 02:15
import ApolloClient config in index.js
import React from "react";
import ReactDOM from "react-dom";
import { ApolloProvider } from "@apollo/react-hooks";
import clientConfig from "./graphql.config";
import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
ReactDOM.render(
<ApolloProvider client={clientConfig}>
<App />
@nixjs
nixjs / dynamic.graphql.js
Created December 23, 2019 02:21
dynamic graphql
export default function (moduleName: any,graphql: any) {
let {mutations,queries} = graphql;
return {
subscriptions: graphql.subscriptions,
queries: {
[`list${moduleName}`]: async (_: any, args: any, g: any) => {
return queries[`list${moduleName}`](_,args,g);
},
[`view${moduleName}`]: async (_: any, args: any, g: any) => {
return queries[`view${moduleName}`](_,args,g);
@nixjs
nixjs / index.js
Created January 13, 2020 13:59
Config nodejs with firebase functions and apollo server express
const functions = require("firebase-functions");
const express = require("express");
const { ApolloServer } = require("apollo-server-express");
const { schema } = require("./graphql/index");
const app = express();
const server = new ApolloServer({
schema
});
server.applyMiddleware({ app, path: "/", cors: true });
@nixjs
nixjs / utils.js
Last active January 13, 2020 14:48
const admin = require("firebase-admin");
const serviceAccount = require("./privatekey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "FIREBASE_DATABASE"
});
const DATABASE_NODE_USER = "users";
const DATABASE_NODE_REF = admin.database();
@nixjs
nixjs / user.js
Created January 13, 2020 14:42
Retrieving Data
const { DATABASE_NODE_REF, DATABASE_NODE_USER } = require("./utils");
const getUsers = () =>
DATABASE_NODE_REF.ref(DATABASE_NODE_USER)
.once("value")
.then(snap => snap.val())
.then(val => Object.keys(val).map(key => val[key]));
const addUser = async (_root, args) => {
const user = {
@nixjs
nixjs / gitignore cache
Created January 29, 2020 03:23
Clear gitignore cache
# remove specific file from git cache
git rm --cached filename
# remove all files from git cache
git rm -r --cached .
git add .
git commit -m ".gitignore is now working"
@nixjs
nixjs / delete branch
Created January 29, 2020 03:25
Git: Delete a branch (local or remote)
## To delete a local branch
git branch -d the_local_branch
## To remove a remote branch (if you know what you are doing!)
git push origin --delete the_remote_branch
@nixjs
nixjs / getClosestStation.js
Created February 20, 2020 09:34
haversine, get closest station
export const getClosestStation = (lat, lng, data) => {
const results = [];
data.forEach(element => {
const _dummy = haversine(lat, lng, element.latitude, element.longitude);
results.push({ ...element, distance: _dummy });
});
const min = Math.min.apply(
null,
results.map(item => item.distance),
);
@nixjs
nixjs / index.js
Last active April 7, 2020 09:43
Kill a process on a port on ubuntu
1. sudo netstat -antlp | grep <PORT> OR lsof -i:3000
Ex: sudo netstat -antlp | grep 3002
2. kill -9 <PID>
Ex: kill -9 18026