Skip to content

Instantly share code, notes, and snippets.

@arafeek
arafeek / use-state-connection.js
Last active February 6, 2020 03:12
Proof of concept "connect' hook for react-redux style state subscription
import { useDispatch, useSelector } from 'react-redux';
export const useStateConnection = (stateMap, actionMap) => {
const mapState = {};
const mapDispatch = {};
// Map state keys to redux store
if (stateMap) {
Object.keys(stateMap).forEach(key => {
mapState[key] = useSelector(stateMap[key]);
import React from 'react';
import { Animated, Easing } from 'react-native';
import { LinearGradient as SvgLinearGradient, Stop } from 'react-native-svg';
const AnimatedStop = Animated.createAnimatedComponent(Stop);
export class AnimatedLinearGradient extends React.Component<LinearGradientProps> {
constructor(props) {
super(props);
@arafeek
arafeek / gist:0f63785fd8f9b2fcfd8ff14a69e87056
Created October 25, 2018 17:51
componentDidUpdate hook for seeing what props changed in a react component render cycle
componentDidUpdate(oldProps) {
Object.keys(oldProps).forEach((key) => {
if (typeof this.props[key] === 'undefined') {
console.log(`Prop '${key} removed`);
}
if (oldProps[key] !== this.props[key]) {
console.log(`Prop '${key}' changed from ${oldProps[key]} -> ${this.props[key]}`);
}
});
Object.keys(this.props).forEach((key) => {
/*****************************************************************************************
*
* Imports
*
******************************************************************************************/
var express = require('express');
var bodyParser = require('body-parser');
/*****************************************************************************************
@arafeek
arafeek / ytd.py
Created January 23, 2017 06:40
Quick and dirty script for downloading and converting youtube videos to mp3. Requires pytube.
from pytube import YouTube
from sys import argv
from os import system
DOWLOAD_LOCATION = 'videos/'
MP3_LOCATION = 'mp3/'
src = argv[1]
if not(src):
@arafeek
arafeek / ng2-nativescript-opinion.md
Last active January 20, 2016 14:59
My feelings on trying to use NativeScript with Angular2 to build a simple app

The Framework:

  • The documentation for using NativeScript with Angular 2 is pretty sparse. A lot of what I learned came from various repository readme's and logged GitHub Issues. For the most part however, it's quite similar to regular Angular2 development except that instead of using HTML to template UI elements, you now have to use NativeScript's XML templating language.

  • NativeScript itself has decent documentation so it wasn't difficult to use it's provided APIs. In terms of application structure, it feels as if it plays pretty well with Angular2 and I would imagine that you could keep a lot of the same structure between a web and native Angular2 application. NativeScript also seems to provide a more bare bones approach to bridging native mobile APIs. Personally I felt like this could be a positive, as some of the abstraction with react-native can make it difficult to get fine tuned control over components. NativeScript has the benefit of being a 'write once, run anywhere' fram

#!usr/bin/env python
import RPi.GPIO as GPIO
import time
import urllib2
import threading
import json
GPIO.setwarnings(False)
# Use the Broadcom SOC channe numbering system for the outputs
@arafeek
arafeek / gist:856c2f12d24e84fe4f22
Created July 31, 2015 03:41
Walk a complex object via a path string and mutate a variable
function set(obj, property, value) {
var properties = R.split('.',property);
var context = obj;
var i;
for(i=0; i < properties.length -1; i++) {
context = context[properties[i]];
}
context[properties[i]] = value;
}
/**
* The examples provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
* Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN