Skip to content

Instantly share code, notes, and snippets.

View ConnectedReasoning's full-sized avatar

Manuel Hernandez ConnectedReasoning

  • Southern California
View GitHub Profile
@ConnectedReasoning
ConnectedReasoning / arrayToObj.js
Last active August 7, 2019 11:35
converts an array of items into an object containing name-value pairs with null as the value
myObjectOfItems = myArray.reduce((obj, item) => {
obj[item['propertyToIsolate']] = null
return obj
}, {});
return new Promise((resolve, reject) => {
fetch("/api/v1/principal", {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + access_token,
}
})
.then(result => {
@ConnectedReasoning
ConnectedReasoning / companyDal.js
Last active June 26, 2019 16:05
react-native async storage simple db
import AsyncStorage from '@react-native-community/async-storage';
export default class CompanyDal{
constructor(){
this.readCompany = this.readCompany.bind(this);
this.reset = this.reset.bind(this);
this.initialize = this.initialize.bind(this);
@ConnectedReasoning
ConnectedReasoning / filterThings.js
Last active April 23, 2019 20:09
Filter a list of things by filter word
const filterThings = (filter_word, things) =>{
//console.log('filtering on ', filter_word);
let filteredThings = things.filter(thing => {
return thing.startsWith(filter_word);
});
return filteredThings.sort();
}
export default filterThings;
@ConnectedReasoning
ConnectedReasoning / autocompletehandlers.js
Created April 9, 2019 09:50
handlers for autocomplete events
onAutocompleteFocus(){
this.setState({defaultValue:'@'});
this.setState({hideSuggestions:false});
}
onAutocompleteTextChange(context_value){
let suggestions = this.state.suggestions;
let newSuggestions = suggestions.filter(suggestion => {
return suggestion.startsWith(context_value);
});
this.setState({context_value});
@ConnectedReasoning
ConnectedReasoning / brightnessByColor.js
Last active August 6, 2018 19:17 — forked from rafael25/brightnessByColor.js
Calculate brightness value by RGB or HEX color
brightnessByColor(color) {
let luminance = 0;
const isHEX = color.indexOf("#") == 0;
const isRGB = color.indexOf("rgb") == 0
let m, r, g, b;
if (isHEX) {
m = color.substr(1).match(color.length == 7 ? /(\S{2})/g : /(\S{1})/g);
if (m) {
r = parseInt(m[0], 16);
@ConnectedReasoning
ConnectedReasoning / brightnessByColor.js
Created August 6, 2018 18:36 — forked from rafael25/brightnessByColor.js
Calculate brightness value by RGB or HEX color
/**
* Calculate brightness value by RGB or HEX color.
* @param color (String) The color value in RGB or HEX (for example: #000000 || #000 || rgb(0,0,0) || rgba(0,0,0,0))
* @returns (Number) The brightness value (dark) 0 ... 255 (light)
*/
function brightnessByColor (color) {
var color = "" + color, isHEX = color.indexOf("#") == 0, isRGB = color.indexOf("rgb") == 0;
if (isHEX) {
var m = color.substr(1).match(color.length == 7 ? /(\S{2})/g : /(\S{1})/g);
if (m) var r = parseInt(m[0], 16), g = parseInt(m[1], 16), b = parseInt(m[2], 16);
@ConnectedReasoning
ConnectedReasoning / reactcomponent.js
Created June 28, 2018 20:07
react component skeleton
import React from 'react';
export default class Home extends React.Component{
render(){
return()
}
}
const path = require('path');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const extractSass = new ExtractTextPlugin({
filename: "[name].[contenthash].css",
disable: process.env.NODE_ENV === "development"
});
module.exports = {
{
"name": "packer",
"version": "0.0.1",
"private": true,
"description": "API packer",
"scripts": {
"dev": "webpack-dev-server",
"build": "webpack",
"watch": "webpack --watch"
},