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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / recursiveObjectAndArray.js
Created February 7, 2017 19:05
A recursive fn over an array and then the props of an object
const buildObject = actions => {
const buildObjectRecursive = (actions, result) => {
for (let key in actions) {
if (actions[key].activity !== 'branch') {
result[actions[key].name] = {
...actions[key]
};
}
for (let k in actions[key]) {
@keyserfaty
keyserfaty / envs.js
Last active March 22, 2017 13:37
Setting different environments in FE
// defaults/index.js
import development from './development';
import production from './production';
export default {
development,
production
}[process.env.NODE_ENV || 'development'];