Skip to content

Instantly share code, notes, and snippets.

View kenbod's full-sized avatar

Ken Anderson kenbod

View GitHub Profile
import java.nio.file.{Paths,Files}
object Process {
def fileExists(path: String): Boolean = {
Files.exists(Paths.get(path))
}
def validInput(args: Array[String]): Boolean = {
val onlyOne = args.length match {
@kenbod
kenbod / import.rb
Created March 5, 2015 19:14
A script to import tweets into MongoDB
require 'bundler/setup'
require 'date'
require 'json'
require 'mongo'
require 'time'
include Mongo
def print_message(message)
@kenbod
kenbod / ImportTweets.md
Last active August 29, 2015 14:16
Ruby Program to Import Tweets into CouchDB

import_tweets.rb

This program shows how to import a set of tweets into a CouchDB database. It is hard coded with knowledge of the particular file that needs to be imported but those aspects of the program can easily be generalized. I make use of Typhoeus to make the actual GET and PUT requests that are needed.

The program also shows how to implement a command-line "spinner" where the program updates just a single line of text while importing the tweets to show progress.

@kenbod
kenbod / StoreFilesInMongo.md
Last active August 29, 2015 14:15
Store shell script in MongoDB

Storing Files in MongoDB

Here's a quick, two-script example of storing and retrieving the contents of a file in MongoDB.

import_script.rb: reads a file and stores it in MongoDB. Hardwired to use the 'neo4j' start-up script. You can change the name to be anything you want (just update the name that is stored in the 'document' variable too!).

get_script.rb: reads a file from MongoDB and writes it to the file system. Again, this example is hardwired to work with the neo4j script that was used in the import_script.rb file. You can once again update this code to work with any script that you have on your own computer.

These programs are written in Ruby and make use of the 'mongo' gem to access MongoDB.

@kenbod
kenbod / account.js
Created February 11, 2015 15:28
IIFE Example
var account = (function(account_name) {
var number_of_logins = 0;
var profile_name = "";
var login = account_name;
return {
login : function() { return login; },
name : function() { return profile_name; },
setName : function(name) { profile_name = name; },
increment: function() { number_of_logins++; },
count : function() { return number_of_logins; }
@kenbod
kenbod / JavascriptThis.md
Last active August 29, 2015 14:14
Understanding Javascript's this Variable

Understanding Javascript's this variable

When discussing AngularJS in lecture this week, we saw that many of our controllers used the following trick to ensure that functions properly updated a controller's variables.

angular.module('myApp').controller('MyController', [function() {
  var self = this;
  self.myVar = 42;
  self.updateVar = function() {
 self.myVar = 23;