Skip to content

Instantly share code, notes, and snippets.

@ooade
ooade / CircularRotation.js
Last active August 18, 2016 16:52
Hackerrank Warmup Challenge - Circular Array Rotation
function processData(input) {
let lines = input.split('\n');
let arr = lines[1].split(' ');
let k = lines[0].split(' ')[1]; // No of spins
let n = arr.length;
for (var i = 2, l = lines.length; i < l; i++) { // First two lines are for k, n and arr so let's skip em
let pos = (n + (lines[i] - (k % n))) % n; // This does the magic!
console.log(arr[pos]);
}
@ooade
ooade / main.js
Last active July 21, 2016 22:49
Wrapup
// Grab the react and react-dom pkgs -->
import React from 'react';
import ReactDOM from 'react-dom';
// Grab Router, Route and browserHistory from react-router ->
import { Router, Route, IndexRoute, browserHistory } from 'react-router';
// Grab Navigation, signin and resource components -->
import Navigation from '../components/navigation';
import SignIn from '../components/signin';
import React, { Component } from 'react';
// Grab the {createContainer} from react-meteor-data pckg and react-router pckg
import { createContainer } from 'meteor/react-meteor-data';
import { browserHistory } from 'react-router';
// Wrap our component in a function with the ComposedComponent as an argument
// ComposedComponent is the component to be rendered
export default function(ComposedComponent) {
class RequireAuth extends Component {
@ooade
ooade / main.js
Created July 21, 2016 22:03
Setup React Router
// Grab the react and react-dom pkgs -->
import React from 'react';
import ReactDOM from 'react-dom';
// Grab Router, Route and browserHistory from react-router ->
import { Router, Route, IndexRoute, browserHistory } from 'react-router';
// Grab Navigation, signin and resource components -->
import Navigation from '../components/navigation';
import SignIn from '../components/signin';
@ooade
ooade / main.js
Created July 21, 2016 21:29
Main JS file with react-router
// Grab the react and react-dom pkgs -->
import React from 'react';
import ReactDOM from 'react-dom';
// Grab Router, Route and browserHistory from react-router ->
import { Router, Route, IndexRoute, browserHistory } from 'react-router';
// Grab Navigation component -->
import Navigation from '../components/navigation';
@ooade
ooade / navigation.js
Last active July 21, 2016 21:43
Navigation bar
import React from 'react';
import { Link } from 'react-router';
export default () => {
return (
<nav className="navbar navbar-fixed-top navbar-dark bg-primary">
<a className="navbar-brand"> Auth Routes (HOC) </a>
<ul className="nav navbar-nav pull-xs-right">
<li className="nav-item active">
<Link className="nav-link" to="/"> Home </Link>
@ooade
ooade / main.js
Created July 21, 2016 19:57
Higher Order Component II
// Grab the react and react-dom pkg
import React from 'react';
import ReactDOM from 'react-dom';
// Write an App Component
const App = () => {
return (
<div> Hello World! </div>
);
};
@ooade
ooade / main.html
Last active July 21, 2016 19:39
Higher Order Components
<head>
<title>My App</title>
</head>
<body>
<div class="app"></div> <!-- We use class here because we're not in the react environment, so don't mix things up -->
</body>
@ooade
ooade / d3.geo.projection.min.js
Created July 7, 2016 08:39
Map Data Across the Globe
!function(){function t(t,a){return{type:"Feature",id:t.id,properties:t.properties,geometry:n(t.geometry,a)}}function n(t,a){if(!t)return null;if("GeometryCollection"===t.type)return{type:"GeometryCollection",geometries:object.geometries.map(function(t){return n(t,a)})};if(!la.hasOwnProperty(t.type))return null;var r=la[t.type];return d3.geo.stream(t,a(r)),r.result()}function a(){}function r(t){if((n=t.length)<4)return!1;for(var n,a=0,r=t[n-1][1]*t[0][0]-t[n-1][0]*t[0][1];++a<n;)r+=t[a-1][1]*t[a][0]-t[a-1][0]*t[a][1];return 0>=r}function e(t,n){for(var a=n[0],r=n[1],e=!1,o=0,i=t.length,h=i-1;i>o;h=o++){var u=t[o],M=u[0],s=u[1],c=t[h],f=c[0],v=c[1];s>r^v>r&&(f-M)*(r-s)/(v-s)+M>a&&(e=!e)}return e}function o(t){return t?t/Math.sin(t):1}function i(t){return t>0?1:0>t?-1:0}function h(t){return t>1?pa:-1>t?-pa:Math.asin(t)}function u(t){return t>1?0:-1>t?ba:Math.acos(t)}function M(t){return t>0?Math.sqrt(t):0}function s(t){function n(t,n){var a=Math.cos(t),e=Math.cos(n),o=Math.sin(n),i=e*a,h=-((1-i?Math.log(.5*(1+i)
@ooade
ooade / projectEuler13.js
Created June 26, 2016 13:47
Project Euler 13 JavaScript Solution
const num =
"37107287533902102798797998220837590246510135740250\n" +
"46376937677490009712648124896970078050417018260538\n" +
"74324986199524741059474233309513058123726617309629\n" +
"91942213363574161572522430563301811072406154908250\n" +
"23067588207539346171171980310421047513778063246676\n" +
"89261670696623633820136378418383684178734361726757\n" +
"28112879812849979408065481931592621691275889832738\n" +
"44274228917432520321923589422876796487670272189318\n" +
"47451445736001306439091167216856844588711603153276\n" +