Skip to content

Instantly share code, notes, and snippets.

View MrToph's full-sized avatar
⁉️

Christoph Michel MrToph

⁉️
View GitHub Profile
// Originally from https://raw.githubusercontent.com/EOSIO/eosjs/v16.0.9/src/format.js
// eosjs2 does not have this function
import Long from 'long';
function bytesToHex(bytes) {
let leHex = '';
for (const b of bytes) {
const n = Number(b).toString(16);
leHex += (n.length === 1 ? '0' : '') + n;
}
@MrToph
MrToph / Axis.js
Created June 21, 2017 21:16
Charts in React Native with React-Native-SVG and D3.js
import React, { Component, PropTypes } from 'react'
import { G, Line, Path, Rect, Text } from 'react-native-svg'
import * as d3scale from 'd3-scale'
import { dateToShortString } from '../utils'
export default class Axis extends Component {
static propTypes = {
width: PropTypes.number.isRequired,
ticks: PropTypes.number.isRequired,
x: PropTypes.number,
@MrToph
MrToph / google-drive.js
Last active April 16, 2024 12:36
Google Drive API v3 fetch
import GoogleSignIn from 'react-native-google-sign-in'
const url = 'https://www.googleapis.com/drive/v3'
const uploadUrl = 'https://www.googleapis.com/upload/drive/v3'
const boundaryString = 'foo_bar_baz' // can be anything unique, needed for multipart upload https://developers.google.com/drive/v3/web/multipart-upload
let apiToken = null
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
d3.csv('data.csv', (err, data) => {
if (err) {
console.log(err)
return
}
ReactDOM.render(
<App width={960} height={640} data={data} />,
document.getElementById('root'),
)
})
import React, { Component, PropTypes } from 'react'
import { G, Line, Text } from 'react-native-svg'
import * as d3scale from 'd3-scale'
export default class Axis extends Component {
static propTypes = {
width: PropTypes.number.isRequired,
ticks: PropTypes.number.isRequired,
x: PropTypes.number,
y: PropTypes.number,
import React, { Component, PropTypes } from 'react'
import { View, UIManager, findNodeHandle, TouchableOpacity } from 'react-native'
import Icon from 'react-native-vector-icons/MaterialIcons'
const ICON_SIZE = 24
export default class PopupMenu extends Component {
static propTypes = {
// array of strings, will be list items of Menu
actions: PropTypes.arrayOf(PropTypes.string).isRequired,
import Curve from './Curve';
export default class PeanoCurve extends Curve {
createData (recLevel) {
this.points = [];
this.recLevel = recLevel;
if (recLevel <= 0) return;
// maxSize is used for rescaling point coordinates to [0,1]
this.maxSize = Math.pow(3, recLevel) - 1; // 3^recLevel - 1 will be the max coordinate of the data.
this.createDataRecursive(0, 0, Math.pow(3, recLevel), 0, 0);
return this.points;
import Curve from './Curve';
export default class HilbertCurve extends Curve {
constructor () {
super();
}
createData (recLevel) {
this.points = [];
this.recLevel = recLevel;
if(recLevel <= 0) return;