Skip to content

Instantly share code, notes, and snippets.

@ooade
ooade / hackerrank_kangaroo.js
Last active August 27, 2016 11:24
Hackerrank Implementation Challenge (Kangaroo)
function main() {
var x1_temp = readLine().split(' ');
var x1 = parseInt(x1_temp[0]);
var v1 = parseInt(x1_temp[1]);
var x2 = parseInt(x1_temp[2]);
var v2 = parseInt(x1_temp[3]);
// return NO, if the first or second kangaroo is far ahead of each other.
if ((x2 > x1 && v2 > v1) || (x1 > x2 && v1 > v2)) {
console.log("NO");
@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)