Skip to content

Instantly share code, notes, and snippets.

View JoaoCnh's full-sized avatar
🎯
Focusing

João Cunha JoaoCnh

🎯
Focusing
View GitHub Profile
@JoaoCnh
JoaoCnh / package.json
Created July 4, 2017 22:00
music-react-demo package.json dependencies
"devDependencies": {
"autoprefixer": "^7.1.1",
"babel-core": "^6.25.0",
"babel-eslint": "^7.2.3",
"babel-loader": "^7.0.0",
"babel-plugin-syntax-decorators": "^6.13.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
@JoaoCnh
JoaoCnh / .babelrc
Created July 4, 2017 22:14
music-react-demo - .babelrc
{
"plugins": [
"transform-class-properties",
"syntax-decorators",
"transform-decorators-legacy"
],
"presets": [
["es2015", { "modules": false }],
"react",
"stage-0"
@JoaoCnh
JoaoCnh / webpack.config.js
Created July 4, 2017 22:28
music-react-demo - webpack
const webpack = require('webpack');
const path = require('path');
const DashboardPlugin = require('webpack-dashboard/plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const SpritePlugin = require('svg-sprite-loader/plugin');
const autoprefixer = require('autoprefixer');
const nodeEnv = process.env.NODE_ENV || 'development';
@JoaoCnh
JoaoCnh / package.json
Last active July 4, 2017 22:40
music-react-demo - scripts package.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack-dashboard -t \"music react demo\" -- webpack-dev-server",
"build": "rm -rf ./build && NODE_ENV=\"production\" webpack",
"preview": "rm -rf ./build && NODE_ENV=\"production\" webpack-dashboard -t 'Preview - music react demo' -- webpack-dev-server"
},
@JoaoCnh
JoaoCnh / index.js
Created July 5, 2017 22:20
react-native-android-voice example
// Import the package
import SpeechAndroid from 'react-native-android-voice';
...
async _buttonClick() {
try{
// THIS EASY!
var spokenText = await SpeechAndroid.startSpeech("Speak into the Mic!", SpeechAndroid.GERMAN);
ToastAndroid.show(spokenText , ToastAndroid.LONG);
}catch(error){
@JoaoCnh
JoaoCnh / badcode.js
Last active July 9, 2017 20:16
bad code
if (data.length === 0 && helperClass.isValid(Math.ceil(data.someValue))) {
runFunctionA(data);
} else {
runFunctionB(data);
}
@JoaoCnh
JoaoCnh / goodcode.js
Last active July 10, 2017 19:55
refactored code
const dataIsEmpty = data.length === 0;
const valueCeil = Math.ceil(data.someValue);
const valueCeilIsValid = helperClass.isValid(valueCeil);
if (dataIsEmpty && valueCeilIsValid) {
runFunctionA(data);
} else {
runFunctionB(data);
}
@JoaoCnh
JoaoCnh / badrefactor.js
Last active July 10, 2017 19:54
bad refactoring
const dataIsEmpty = data.length === 0;
const valueCeil = Math.ceil(data.someValue);
const valueCeilIsValid = helperClass.isValid(valueCeil);
dataIsEmpty && valueCeilIsValid ? runFunctionA(data) : runFunctionB(data);
@JoaoCnh
JoaoCnh / jquery-example.js
Created July 9, 2017 22:46
caching jQuery lookups
// bad
function setSidebar() {
$('.sidebar').hide();
// ...
$('.sidebar').css({
'background-color': 'pink',
});
}
@JoaoCnh
JoaoCnh / index.js
Last active July 9, 2017 23:12
js optimized for loop
// normal loop
for (var i = 0; i < array.length; i++) {
console.log(array[i]);
}
// optimized loop
for (var i = array.length - 1; i >= 0; i--) {
console.log(array[i]);
}