Skip to content

Instantly share code, notes, and snippets.

View diegocasmo's full-sized avatar
👨‍💻

Diego Castillo diegocasmo

👨‍💻
View GitHub Profile
@diegocasmo
diegocasmo / fft_pseudocode.txt
Last active June 9, 2022 20:50
Pseudocode of the 'The Fast Fourier Transform Algorithm'
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)
@diegocasmo
diegocasmo / Tab.js
Last active September 3, 2021 06:06
Source code for implementing a React <Tabs/> component.
import React, {PropTypes} from 'react';
export const Tab = (props) => {
return (
<li className="tab">
<a className={`tab-link ${props.linkClassName} ${props.isActive ? 'active' : ''}`}
onClick={(event) => {
event.preventDefault();
props.onClick(props.tabIndex);
}}>
@diegocasmo
diegocasmo / karatsuba.spec.rb
Created February 9, 2017 14:36
Tests for an implementation of the Karatsuba multiplication algorithm in Ruby
require 'minitest/autorun'
require './karatsuba'
describe Karatsuba do
before do
@karatsuba = Karatsuba.new
end
describe "#multiply" do
it "should multiply small numbers of equal size" do
@diegocasmo
diegocasmo / karatsuba.rb
Last active July 15, 2020 19:09
An implementation of Karatsuba multiplication algorithm in Ruby
class Karatsuba
# Multiply two numbers using the Karatsuba
# multiplication algorithm
def multiply(num_1, num_2)
if num_1 < 10 || num_2 < 10
return num_1 * num_2
end
m_2 = [num_1.to_s.length, num_2.to_s.length].max/2
# Split the digit sequences about the middle
high_1, low_1 = num_1.divmod(10**m_2)
@diegocasmo
diegocasmo / mine-remoteok-io-listings.js
Last active March 3, 2019 20:38
Text processing script to mine https://remoteok.io/ job listings' titles.
// 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(' ') }));
@diegocasmo
diegocasmo / Tabs.js
Created February 9, 2017 14:40
Implementation of a <Tabs/> component in React
export class Tabs extends Component {
constructor(props, context) {
super(props, context);
this.state = {
activeTabIndex: this.props.defaultActiveTabIndex
};
this.handleTabClick = this.handleTabClick.bind(this);
}
@diegocasmo
diegocasmo / dfs.spec.rb
Created March 20, 2017 16:02
Tests for the implementation of the depth first search algorithm.
require 'minitest/autorun'
require './depth_first_search_undirected'
describe DFS do
before do
graph = {
:a => [:b, :e],
:b => [:a],
:c => [:d, :g, :h],
@diegocasmo
diegocasmo / dfs.rb
Created March 20, 2017 16:01
An implementation of the depth first search algorithm for undirected graphs.
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
@diegocasmo
diegocasmo / todo_delete_actions.txt
Created March 13, 2017 14:06
Todo DELETE actions.
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
@diegocasmo
diegocasmo / create_middleware.js
Created March 13, 2017 14:07
Utility method that allows to create a Redux middleware and execute custom code before or after an action is dispatched.
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