Skip to content

Instantly share code, notes, and snippets.

View diegocasmo's full-sized avatar
👨‍💻

Diego Castillo diegocasmo

👨‍💻
View GitHub Profile
@diegocasmo
diegocasmo / upwork_count_work_diary_slots_by_task.js
Last active November 17, 2016 20:01
upwork_count_work_diary_slots_by_task.js
var elements = document.getElementsByClassName('o-activity');
var elementsArr = [];
for(var i = 0; i < elements.length; i++)
{
elementsArr.push(elements.item(i).text);
}
var uniqueCount = {};
elementsArr.forEach(function(i) {
uniqueCount[i] = (uniqueCount[i]||0)+1;
});
@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.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 / 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 / tabs_hierarchy.js
Created February 9, 2017 14:39
<Tabs/> component hierarchy concept
<Tabs>
<Tab iconClassName={'icon-class-0'} linkClassName={'link-class-0'}>
<p>content 0</p>
</Tab>
<Tab iconClassName={'icon-class-1'} linkClassName={'link-class-1'}>
<CustomComponent propA={'foo'} propB={this.handleSomething}/>
</Tab>
</Tabs>
@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 / Tab.js
Created February 9, 2017 14:41
Implementation of a <Tab/> component in 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);
}}>
<i className={`tab-icon ${props.iconClassName}`}/>
</a>
@diegocasmo
diegocasmo / merge_sort.spec.rb
Created February 13, 2017 18:37
Tests for an implementation of the Merge Sort algorithm in Ruby
require 'minitest/autorun'
require './merge_sort'
describe MergeSort do
before do
@merge_sort = MergeSort.new
end
describe "#sort" do
it "should sort an array of 1 element" do
@diegocasmo
diegocasmo / merge_sort.rb
Created February 13, 2017 18:37
An implementation of the Merge Sort algorithm in Ruby
class MergeSort
# Sorts an array using the merge sort algorithm
def sort(arr)
length = arr.length
if length > 1
mid = (length/2).floor
return merge(sort(arr[0..(mid - 1)]), sort(arr[mid..length]))
else
return arr
end
@diegocasmo
diegocasmo / Provider.jsx
Last active February 20, 2017 15:24
This component implements the context feature, and exposes the prop called appData to other components. The whole application is going to be wrapped by it.
class Provider extends React.Component {
getChildContext() {
return {appData: this.props.appData};
}
render() {
return(
<div>
{this.props.children}
</div>