Skip to content

Instantly share code, notes, and snippets.

View srowhani's full-sized avatar

Seena Rowhani srowhani

View GitHub Profile
#!/usr/bin/env node
/**
* Suppose you want to place gasoline stations at various locations along a highway.
* For simplicity, let us model the highway as the X-axis.
* You have a list of potential locations for the gas stations x1 , x2 , . . . , xn .
* For each location, you have an estimated revenue r1 , r2 , . . . , rn .
* However, for environmental reasons, the distance between two gas stations must be at least 20 kilometers,
* that is for two consecutive gas stations xi and xj, we must have xj − xi ≥ 20.
* Design a placement algorithm that will optimize your estimated revenue.
* For example, if your possible station locations are (2, 17, 24, 32, 48),
Array.prototype.equals = function (array) {
// if the other array is a falsy value, return
if (!array)
return false;
// compare lengths - can save a lot of time
if (this.length != array.length)
return false;
for (var i = 0, l=this.length; i < l; i++) {
@srowhani
srowhani / .deploy.sh
Last active October 21, 2016 17:56
Helps deploy stuff
#!/bin/bash
set -ev
# Blow up current dist
rm -rf dist;
# Build it
ember build --prod;
# Initialize dist as it's own repo
URL=$(git remote get-url origin);
cd dist;
git init;
@srowhani
srowhani / _def.js
Last active October 17, 2016 23:27
MWT algorithm implemented in ES6
let Point = function (x, y) {
this.x = x
this.y = y
}
let Triangle = function (p1, p2, p3) {
this.p1 = p1
this.p2 = p2
this.p3 = p3
}
@srowhani
srowhani / example.json
Last active October 6, 2016 00:53
JSONAPI Example ember
{
"data": [
{
"_id": "ember-frost-navigation@5.0.3",
"type": "repository",
"attributes": {
"name": "ember-frost-navigation",
"source": "GitHub",
"user": "",
"version": "5.0.3",
@srowhani
srowhani / components.my-component.js
Created August 3, 2016 18:54
Asana Style Editor
import Ember from 'ember';
export default Ember.Component.extend({
didInsertElement () {
if (this.get('isFocused'))
this.$('input').focus()
}
});
#include <stdio.h>
#include <stdlib.h>
int str_len (char* myStr)
{
int length = 0;
while (1)
{
if (myStr[length] == '\0')
break;