Skip to content

Instantly share code, notes, and snippets.

View woss's full-sized avatar
🛸

Daniel Maricic woss

🛸
View GitHub Profile
@woss
woss / Object Flatten
Created October 5, 2019 18:02 — forked from penguinboy/Object Flatten
Flatten javascript objects into a single-depth object
var flattenObject = function(ob) {
var toReturn = {};
for (var i in ob) {
if (!ob.hasOwnProperty(i)) continue;
if ((typeof ob[i]) == 'object') {
var flatObject = flattenObject(ob[i]);
for (var x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
const isItIntrospectionQuery = (query: string): boolean => {
return query.includes('IntrospectionQuery')
}
const postgraphileOptions = {
async pgSettings(req: Request) {
if (isItIntrospectionQuery(JSON.stringify(req.body))) return {}
return {
role: 'DATABASE_VISITOR',
Verifying my Blockstack ID is secured with the address 1BsPosJc5tAbPPbCZfR2A1qUirji1344ER https://explorer.blockstack.org/address/1BsPosJc5tAbPPbCZfR2A1qUirji1344ER
@woss
woss / Timeline.ts
Created December 22, 2018 23:51
apoll with remote api sync local state
// @flow
import React, {Component} from 'react'
import {Query} from 'react-apollo'
import gql from 'graphql-tag'
import {withStyles} from '@material-ui/core/styles'
import Grid from '@material-ui/core/Grid'
import CircularProgress from '@material-ui/core/CircularProgress'
import Gallery from 'react-photo-gallery'
import SelectedImage from '../../components/Image/SelectedImage'
@woss
woss / PhotoConnection.ts
Created December 13, 2018 10:53
Prisma Graphql Connection Resolvers
import {PhotoConnectionResolvers} from '../generated/graphqlgen'
export const PhotoConnection: PhotoConnectionResolvers.Type = {
...PhotoConnectionResolvers.defaultResolvers,
pageInfo: (parent, args, ctx, info) => {
// here args is empty
return ctx.db.photosConnection(args).pageInfo()
},
edges: (parent, args, ctx, info) => {
import * as mh from 'multihashes'
import * as fs from 'fs'
import * as path from 'path'
const imagePath = path.resolve(rootPath, image)
const buf = fs.readFileSync(imagePath)
const hash = mh.encode(buf, 'sha2-256')
consle.log(mh.toB58String(hash))
@woss
woss / apollo-fetch.js
Created September 17, 2018 16:32 — forked from stubailo/apollo-fetch.js
Call a GraphQL API with apollo-fetch
const { createApolloFetch } = require('apollo-fetch');
const fetch = createApolloFetch({
uri: 'https://1jzxrj179.lp.gql.zone/graphql',
});
fetch({
query: '{ posts { title }}',
}).then(res => {
console.log(res.data);
@woss
woss / Warning: context.done called twice within handler .js
Last active February 1, 2018 11:44
not, this gist is using FLOW. if you would like to test it without it remove TYPES
import type {
APIGatewayEvent,
Context,
ProxyCallback as PC,
} from 'flow-aws-lambda'
/**
*
* @param {*} cb AWS lambda callback
* @param {*} message
* @param {*} status
@woss
woss / bitcolor.js
Created December 17, 2017 17:48 — forked from lrvick/bitcolor.js
Javascript functions for doing fast binary/hex/RGB color conversions using bitwise operations.
// convert 0..255 R,G,B values to binary string
RGBToBin = function(r,g,b){
var bin = r << 16 | g << 8 | b;
return (function(h){
return new Array(25-h.length).join("0")+h
})(bin.toString(2))
}
// convert 0..255 R,G,B values to a hexidecimal color string
RGBToHex = function(r,g,b){
import falcon
import json
class TabletsCollection(object):
def on_get(self, req, res):
params = {}
for param in req.params:
params[param] = req.params[param]
res.body = json.dumps({