Skip to content

Instantly share code, notes, and snippets.

"use strict"
const buildLetterMap = (str) => {
let letterMap = {};
str.split("").forEach(function(letter) {
if(letterMap[letter]) {
letterMap[letter] = letterMap[letter] + 1;
} else {
letterMap[letter] = 1;
@rastalamm
rastalamm / Flatten Nested Arrays
Last active December 7, 2016 23:28
Write some code, that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4].
'use strict'
const makeMeFlat = (arr) => {
let output = []; //define what we want to eventually return
if (arr && Array.isArray(arr)) { //make sure there is an input and it's an array
for(var i = 0; i < arr.length; i++) { //Loop through input
if (Array.isArray(arr[i])) { //The parameter is an array, we need to look into this; recursively
output = output.concat(makeMeFlat(arr[i])); //Redefine `output` as itself with the array concactenated to it, while recursively looping through the parameter
} else {
output.push(arr[i]); //The parameter is not an array, send it to the output
}
/*jslint es6, node: true */
(function () {
"use strict";
const express = require('express');
const router = express.Router();
const Lesson = require('../models').Lesson;
const getAllLessons = function () {
@rastalamm
rastalamm / gist:3517e26193cd75ec0fb0
Created August 12, 2015 19:53
Implementation of Cordova SMS
angular.module('starter')
.controller('SmsController', ['$ionicPlatform', '$scope', '$cordovaSms',
function($ionicPlatform, $scope, $cordovaSms) {
console.log('inside');
$ionicPlatform.ready(function (){
$scope.sendSms = function (){
var number = '15169650711';
var message = 'Hello World';
@rastalamm
rastalamm / exercise.md
Last active August 29, 2015 14:26 — forked from theRemix/exercise.md
MongoDB Practice

MongoDB Practice

MongoDB Exercise in mongo shell

Connect to a running mongo instance, use a database named mongo_practice.

Document all your queries in a javascript file to use as a reference.

Insert Documents

@rastalamm
rastalamm / intro-mongo.md
Last active August 29, 2015 14:26 — forked from sgnl/intro-mongo.md
MongoDB... COME ON DOOOOOOOWN

Before starting run the commands brew doctor and then brew update

Unix Users please install using the docs

Install Mongodb via Homebrew

$ brew install mongodb

Once brew is done installing, take note of the Caveats section that is printed to your console. Just like what we did previously for postgres it might be best to create a symlink then two aliases to start and stop the mongo progress.

  • Start your mongodb service
@rastalamm
rastalamm / README.md
Last active August 29, 2015 14:25 — forked from thgaskell/README.md
Basic Authentication with Passport

Basic Authentication with Passport

Basic authentication is one of the simplest authentication strategies because it doesn't require cookies, sessions, or even a login form! Instead, it uses HTTP headers which means credentials are transmitted on each request.

Installation

You will need to install passport and passport-http. The passport-http module is what allows you set up the Basic Authentication Scheme, in addition to a couple other authentication strategies.

$ npm install express passport passport-http --save
@rastalamm
rastalamm / gist:5e68e3db2a48984189b1
Created July 18, 2015 20:15
Creating keep Alive Agent if you run into the 'EADDRNOTAVAIL' problem. (You ran out of sockets)
var keepAliveAgent = new http.Agent({
keepAlive: true,
keepAliveMsecs : 200 });
var options = {
hostname : HOST,
port : PORT,
method : 'POST',
agent : keepAliveAgent
}

Gulp + Sass + LiveReload

Goals

To have a gulp workflow that with a single process,

  1. watches for any sass changes, then compiles sass source into css
  2. watches for any changes in the public directory, triggers live-reload
  3. serves your static content in public/
@rastalamm
rastalamm / README.md
Last active August 29, 2015 14:25 — forked from thgaskell/README.md