Skip to content

Instantly share code, notes, and snippets.

View keyserfaty's full-sized avatar
🏠
Working from home

karen keyserfaty

🏠
Working from home
View GitHub Profile
@keyserfaty
keyserfaty / extractEndpointNames2.js
Last active February 7, 2017 19:05
extractEndpointNames
function extractEndpointNames (json) {
function recurExtract (json, result) {
for (let key in json[0]) {
if (Array.isArray(json[0][key])) {
recurExtract(
json[0][key],
result
)
} else {
if (key === 'args') {
@keyserfaty
keyserfaty / rxjs-twitter.js
Created December 17, 2016 12:40
RxJS Twitter Suggested Users
var refreshButton = document.querySelector('.refresh')
var refreshClickStream = Rx.Observable
.fromEvent(refreshButton, 'click')
var startupRequest = Rx.Observable
.just('https://api.github.com/users')
var reqOnRefreshStream = refreshClickStream
.map(event => {
@keyserfaty
keyserfaty / routing.js
Created December 9, 2016 16:33
Basic Routing
const d = document;
//* Basic setup
const first = d.createElement('a');
first.innerText = 'Holi Primero';
first.setAttribute('href', '#/first')
const second = d.createElement('a');
second.innerText = 'Holi Segundo';
second.setAttribute('href', '#/second')
@keyserfaty
keyserfaty / ramdavsjs.js
Created December 2, 2016 16:44
Some fn in Javascript vs Ramda
import { when, equals, always, __ } from 'ramda'
//* Return a value when a certain value is provided
const parseTitleRamda = value => (
when(equals('workflow', __), always('endpoints'))(value),
when(equals('integration', __), always('connections'))(value)
)
const parseTitle = title => {
if (title === 'workflow') return 'endpoints';
@keyserfaty
keyserfaty / saga.js
Last active September 27, 2018 22:25
An example of a saga making multiple requests with unknown bodies
export function * fetchAllWorker (action) {
yield put(actions.fetchAll.start())
const { types } = action.payload
for (let i = 0; i < types.length; i++) {
const { res, error } = yield call(get, `js_helpers/${types[i]}`)
if (res.status > 201 || error) {
return put(actions.fetchAll.failure({ error }))
@keyserfaty
keyserfaty / curry.js
Created October 13, 2016 17:05
A small curry for future reference
import { omit, pipe, assoc } from 'ramda';
const stringifyJson = e => JSON.stringify(e, null, '\t');
const parsedJson = e => JSON.parse(e.replace('\t', ''));
const moduleDefinitionInput = pipe(omit(['staticDisplayName']), stringifyJson);
const moduleDefinitionOutput = pipe(parsedJson, assoc('staticDisplayName', staticDisplayName));
moduleDefinitionInput(content);
moduleDefinitionOutput(content);
@keyserfaty
keyserfaty / words.js
Created September 21, 2016 14:21
A list of two-syllable words
const CONSONANTS = ['q', 'w', 'r', 't', 'y', 'p', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm'];
const VOCALS = ['a', 'e', 'i', 'o', 'u'];
const buildPair = (cons, vocal) =>
cons
.reduce((res, e) => {
const pair = VOCALS.map(v => e + v);
res.push(pair);
@keyserfaty
keyserfaty / scala-fn.md
Last active September 18, 2016 13:50
Some Scala functions turned Javascript

Factorial

Scala

def factorial(n: Int) = {
  def tailFactorial(n: Int, acc: Int): Int =
    if (n == 0) acc else tailFactorial(n - 1, acc * n)

  tailFactorial(n, 1)
@keyserfaty
keyserfaty / nightwatch-react.md
Last active July 27, 2022 20:32
How to write a simple `Nightwatch` test for a `React` app?

How to write a simple Nightwatch test for a React app?

Nightwatch is a testing tool made in Node and Selenium to test browser apps. Long story short you can set it to navigate (really, truly, navigate) your site to test it as if it was a real person.

After you setup your environment, add your tests and run them Nightwatch will open a browser and start interacting with your site in realtime (you can see the whole thing). It will starting clicking around based on what you told it it should click and test if it encounters what you told it it should encounter.

Ok, so lets get to it!

I'm not gonna focus much in the setting up process (I'm much more interested in the API and the use cases) but this is a summary of what you should do in Mac: (full instructions in the Nightwatch website)

@keyserfaty
keyserfaty / handling-refs-es6-classes.md
Last active September 8, 2016 18:15
Handling refs in React with ES6 classes

What are React's refs?

Refs are a reference to the DOM node created by a React element after rendering. There are some scenarios when you need to operate on the node element (the actual DOM node that is rendered to the view) rather than the element used by React in the virtual DOM. My case scenario: I needed to let the user download an image that was generated with a canvas in the virtual DOM. The only way to do this was to wait for the page to be fully rendered and do some stuff on the canva's node element.

With ref you can access the node element that an element from the virtual DOM will generate after its done, like this:

render() {
 return (