Skip to content

Instantly share code, notes, and snippets.

View rcanepa's full-sized avatar

Renzo Canepa rcanepa

View GitHub Profile
@rcanepa
rcanepa / gist:fc29c00c4185c4a13b54
Last active June 9, 2021 21:07
C++ Binary Search (iterative and recursive)
#include <iostream>
#include <stdlib.h>
#include <time.h>
int binary_search(int list[], int length, int to_be_found);
int recursive_binary_search(int list[], int to_be_found, int p, int r);
int main()
{
@rcanepa
rcanepa / gist:5505446c290572a86bec
Last active August 29, 2015 14:15
Python Merge Sort
import random
def merge(left_arr, right_arr):
"""
Receives two ordered lists and returns a ordered
list created from the merge of the other two.
:param left_arr: ordered list
:param right_arr: ordered list
:return: ordered list created from the merge of left_arr and right_arr
@rcanepa
rcanepa / gist:236e1af93969e665268f
Last active August 29, 2015 14:15
Python Insertion Sort
def insertion_sort(arr):
for idx, number in enumerate(arr):
current = idx
previous = idx - 1
if idx > 0:
while arr[current] < arr[previous] and (previous >= 0):
temp = arr[current]
arr[current] = arr[previous]
arr[previous] = temp
current = previous
@rcanepa
rcanepa / gist:4a5e563a0e82780c8459
Last active August 29, 2015 14:15
C++ Selection Sort
#include <iostream>
#include <stdlib.h>
void selection_sort(int *list, int list_length);
int main()
{
int list_length = 30;
int list[list_length];
@rcanepa
rcanepa / gist:31a2e2e987c8b2c2f665
Last active August 29, 2015 14:15
C++ Insertion Sort
#include <iostream>
#include <stdlib.h>
void insertion_sort(int *list, int lenght);
int main(int argc, char const *argv[])
{
int list_length = 30;
int list[list_length];
srand(time(NULL));
@rcanepa
rcanepa / gist:923e04598390a8863033
Created February 19, 2015 01:35
C++ Merge Sort
#include <iostream>
#include <stdlib.h>
/*
This implementation could be improved using
sentinels.
*/
void merge_sort(int *list, int p, int r);
@rcanepa
rcanepa / gist:767040cb76491463287d
Created February 19, 2015 16:49
c++ Quick Sort (random pivot)
#include <iostream>
#include <stdlib.h>
void quick_sort(int *list, int p, int r);
int main(int argc, char const *argv[])
{
int n = 11;
int list[n];
srand(time(NULL));
@rcanepa
rcanepa / gist:229bc46957778629521f
Last active August 16, 2019 00:59
C++ Snippets
/*
Short list of macros and templates from
http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=standardTemplateLibrary
*/
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define pb push_back
#defile all(c) (c).begin(),(c).end()
@rcanepa
rcanepa / richhickey.md
Created November 1, 2015 12:41 — forked from prakhar1989/richhickey.md
richhickey.md

Rich Hickey on becoming a better developer

Rich Hickey • 3 years ago

Sorry, I have to disagree with the entire premise here.

A wide variety of experiences might lead to well-roundedness, but not to greatness, nor even goodness. By constantly switching from one thing to another you are always reaching above your comfort zone, yes, but doing so by resetting your skill and knowledge level to zero.

Mastery comes from a combination of at least several of the following:

@rcanepa
rcanepa / components.clj
Created December 7, 2015 03:24 — forked from Deraen/components.clj
Compojure-api with Component
(ns foobar.components
(:require [com.stuartsierra.component :as component]
[compojure.api.sweet :refer :all]))
(defmethod compojure.api.meta/restructure-param :components
[_ components acc]
(update-in acc [:letks] into [components `(::components ~'+compojure-api-request+)]))
(defn wrap-components [handler components]
(fn [req]