Skip to content

Instantly share code, notes, and snippets.

@johndavedecano
johndavedecano / binary_gap.js
Last active October 1, 2017 06:03
EXAMS - Binary Gap
function solution(A) {
const rep = (A >>> 0)
.toString(2)
.split(1)
.filter(x => x !== "")
.sort(function(a, b) {
return b.length - a.length;
});
return rep.length === 0 ? 0 : rep[0].length;
@johndavedecano
johndavedecano / shotest_sequence.js
Created October 1, 2017 05:28
EXAMS - SHORTEST SEQUENCE
function solution(A) {
let arr = [1];
while (arr[arr.length - 1] < A) {
let prev = arr[arr.length - 1];
let next = prev * 2;
if (next > A) {
prev = arr[arr.length - 2] + 1;
@johndavedecano
johndavedecano / fizzbuzz.js
Last active October 1, 2017 05:03
EXAMS - FIZZBUZZ
function fizzbuzz(num) {
let returnValue = '';
let isFizz = num % 3 === 0;
let isBuzz = num % 5 === 0;
returnValue = (isFizz ? 'Fizz' : '') + (isBuzz ? 'Buzz' : '');
if (returnValue !== '') {
console.log(returnValue + ' - ' + num);
@johndavedecano
johndavedecano / requireAuthHOC.js
Created July 19, 2017 14:07
ReactJS Redux Authentication HOC
import React from 'react';
import { connect } from 'react-redux';
export default function requireAuth(WrappedComponent) {
class AuthenticatedComponent extends React.Component {
componentDidMount() {
this.checkAuth(this.props.isLoggedIn);
}
checkAuth(isLoggedIn) {
@johndavedecano
johndavedecano / index.html
Created March 15, 2017 07:51
React Hello World w/ JSBin // source http://jsbin.com/netuji
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.7.3/immutable.min.js"></script>
<script src="https://cdn.jsdelivr.net/lodash/4/lodash.min.js"></script>
<script src="http://fb.me/react-0.13.1.js"></script>
<meta charset="utf-8">
<title>React Hello World w/ JSBin</title>
<style id="jsbin-css">
.imgs-grid {
@johndavedecano
johndavedecano / index.html
Created March 15, 2017 06:38
React Hello World w/ JSBin // source http://jsbin.com/netuji
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.7.3/immutable.min.js"></script>
<script src="https://cdn.jsdelivr.net/lodash/4/lodash.min.js"></script>
<script src="http://fb.me/react-0.13.1.js"></script>
<meta charset="utf-8">
<title>React Hello World w/ JSBin</title>
<style id="jsbin-css">
.imgs-grid {
@johndavedecano
johndavedecano / index.html
Created March 15, 2017 05:17
React Hello World w/ JSBin // source http://jsbin.com/netuji
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.7.3/immutable.min.js"></script>
<script src="https://cdn.jsdelivr.net/lodash/4/lodash.min.js"></script>
<script src="http://fb.me/react-0.13.1.js"></script>
<meta charset="utf-8">
<title>React Hello World w/ JSBin</title>
<style id="jsbin-css">
.imgs-grid {
@johndavedecano
johndavedecano / TimeAgo.jsx
Last active August 22, 2024 16:00
TimeAgo component using date-fns
import React, {Component} from 'react';
import differenceInSeconds from 'date-fns/difference_in_seconds';
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
class TimeAgo extends Component {
componentDidMount() {
if (this.props.isLive) {
this.updateTime();
}
@johndavedecano
johndavedecano / EventSystem.js
Created April 17, 2016 14:38 — forked from minwe/EventSystem.js
Global event system for React.js
var EventSystem = (function() {
var self = this;
self.queue = {};
return {
publish: function (event, data) {
var queue = self.queue[event];
if (typeof queue === 'undefined') {
@johndavedecano
johndavedecano / app.js
Created March 17, 2016 12:42 — forked from lykmapipo/app.js
Ionic / AngularJS service wrapper for Web SQL API / SQLite-Cordova-Plugin
angular.module('myApp', ['ionic', 'myApp.services', 'myApp.controllers'])
.run(function(DB) {
DB.init();
});