Skip to content

Instantly share code, notes, and snippets.

View fakenickels's full-sized avatar
💭
hello this is a mic test, are you listening

Gabriel fakenickels

💭
hello this is a mic test, are you listening
View GitHub Profile
@fakenickels
fakenickels / migrate.sh
Created August 10, 2016 18:35
Meteor app structure revamp migration
mv .meteor/dev_bundle app/.meteor/
mv .meteor/local app/.meteor/
# Delete old stuff
rm -rf node_modules
rm -rf packages
# Delete remaining empty folders
find . -type d -empty -delete
@fakenickels
fakenickels / download_from_route.js
Last active August 21, 2016 17:56
Download a file from the server with fetch HTML5 API and FileSaver.js
function downloadFromRoute({url, data, filename}){
fetch(url, {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'text/json',
},
})
.then(response => response.blob())
.then(blob => saveAs(blob, filename))
import { Mongo } from 'meteor/mongo'
import { Meteor } from 'meteor/meteor'
function addConsoleSpyOn({object, methods, spyFn}){
const oldMethods = methods.reduce((acc,name) => ({...acc, [name]: object[name]}), {})
methods.forEach(method => {
object[method] = function(...args){
spyFn({instance: this, args, method})
@fakenickels
fakenickels / renderField.js
Created March 20, 2017 19:29
renderField for reduxForm and react native
// @flow
import React, { Component } from 'react'
import {
Picker,
} from 'react-native'
import {
find,
get,
omit,
} from 'lodash/fp'
@fakenickels
fakenickels / transform-symbol-member.js
Created March 21, 2017 17:52
Fix for rxjs in babel
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*/
'use strict';
/*eslint consistent-return: 0*/
/**
* Transforms function properties of the `Symbol` into
function simpleTemplate(string, object){
return string.replace(/({[^{]+})/g, (group) => object[group.replace(/[{}]/g, '')])
}
simpleTemplate('Something something: {foo} => {bar}', { foo: 'Thing 1', bar: 'Thing 2' })
// => 'Something something: Thing 1 => Thing 2'
@fakenickels
fakenickels / breakthroughs.md
Created April 11, 2017 13:17
Immutability breakthroughs

But returning a new structure everytime it changes isn't slow?

It is in normal cases for JS objects and arrays but immutable data structures are reused "tries" so data is shared across all instances and persistence isn't affected. Tries are crazily efficient and basic all operations (insert, update, delete) resume to an O(1) op.

Comparison

Immutable data equality check is much faster

@fakenickels
fakenickels / commands.md
Created July 25, 2017 19:58
Useful commands

removes all babelrc

$ find node_modules/ -type f -name .babelrc | grep -v packager | xargs rm
import React from "react";
import { View, Text, Modal, TouchableOpacity } from "react-native";
export default class ViewUsingModal extends React.Component {
state = { isModalVisible: false };
toggleModal = () =>
this.setState({ isModalVisible: !this.state.isModalVisible });
render() {
import React from 'react'
import { View, Text, Modal } from 'react-native'
import withState from './withState'
const ViewUsingModal = ({ isModalVisible, toggleModalVisibility, isLoading }) =>
<View>
<TouchableOpacity onPress={toggleModalVisibility}>
<Text>Tap me!</Text>
</TouchableOpacity>