This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get job listings' titles | |
var listings = Array.from(document.getElementsByTagName('h2')) | |
.splice(3) | |
.map(function(x) { return x.innerText }); | |
// Tokenize listings' titles | |
var keywords = [].concat.apply( | |
[], | |
listings.map(function(x) { return x.split(' ') })); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/autorun' | |
require './depth_first_search_undirected' | |
describe DFS do | |
before do | |
graph = { | |
:a => [:b, :e], | |
:b => [:a], | |
:c => [:d, :g, :h], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DFS | |
def initialize(graph={}) | |
@graph = graph | |
@visited = {} | |
end | |
# This implementation of depth-first search visits | |
# only the portion of the graph reachable from the | |
# starting vertex |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {createStore, combineReducers, applyMiddleware} from 'redux' | |
import {redirectMiddleware} from '../middleware/redirect_middleware'; | |
let todoApp = combineReducers(reducers); | |
let store = createStore( | |
todoApp, | |
applyMiddleware(redirectMiddleware) // Apply redirect middleware | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {browserHistory} from 'react-router' | |
export const redirectMiddleware = createMiddleware([ | |
{ | |
// Redirect user to index page on successful TODO delete | |
action: TODO__DELETE__SUCCESS, | |
afterHandler: (storeAPI, action) => { | |
browserHistory.replace({pathname: '/'}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Immutable from 'immutable'; | |
// Helper method for creating a middleware that handles the given set of actions | |
export function createMiddleware(handlers) { | |
return storeAPI => next => action => { | |
const actionHandler = Immutable.List(handlers).find(h => h.action.type === action.type); | |
// Execute custom middleware handler before the action is dispatched | |
if (actionHandler && actionHandler.beforeHandler) { | |
actionHandler.beforeHandler(storeAPI, action); | |
} | |
// Dispatch the action |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TODO__DELETE__INIT // Dispatched when user clicks the delete button | |
TODO__DELETE__SUCCESS // Dispatched when a TODO has been successfully deleted | |
TODO__DELETE__FAILURE // Dispatched if there was a problem while attempting to delete a TODO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/autorun' | |
require './fft' | |
describe FFT do | |
before do | |
@fft = FFT.new | |
end | |
describe "#fft" do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FFT | |
# Input: n coefficients | |
# Output: Point-wise representation of the n coefficients | |
# Vec size must be a power of 2 | |
def fft(vec) | |
return vec if vec.size <= 1 | |
# Split A(x) into its odd and even powers | |
a_even = vec.each_with_index.select { |_, i| i.even? }.map { |i, _| i } | |
a_odd = vec.each_with_index.select { |_, i| i.odd? }.map { |i, _| i } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function FFT(A, ω) | |
Input: Coefficient representation of a polynomial A(x) of degree ≤ n − 1, where n is a power of 2 | |
Output: Value representation A(ω^0), . . . , A(ω^n−1) | |
if ω = 1: return A(1) | |
express A(x) in the form Ae(x^2) + xAo(x^2) | |
call FFT(Ae, ω^2) to evaluate Ae at even powers of ω | |
call FFT(Ao, ω^2) to evaluate Ao at odd powers of ω | |
for j = 0 to n − 1: | |
compute A(ω^j) = Ae(ω^2j) + ω^jAo(ω^2j) |
NewerOlder