Skip to content

Instantly share code, notes, and snippets.

View diamond.rs
// Diamond Kata
fn main() {
let character = &std::env::args().collect::<Vec<String>>()[1];
diamond(character.chars().next().unwrap() as u8)
}
fn diamond(c: u8) {
let max_rows = c - b'A';
let mut rows = Vec::with_capacity(max_rows as usize);
View tree.c
// builds the tree for the secret stage for the binary bomb
// http://blog.carlosgaldino.com/defusing-a-binary-bomb-with-gdb.html
#include <stdio.h>
#include <stdlib.h>
struct node {
int data;
struct node *left;
struct node *right;
};
View msort.erl
-module(msort).
-export([sort/1]).
sort([]) ->
[];
sort([X]) ->
[X];
sort(List) ->
{Xs, Ys} = split(List),
merge(sort(Xs), sort(Ys)).
View person.rs
struct Person {
name: String,
age: u8
}
fn main() {
// only works if compiled with `--test` flag.
// let p = Person::create_with(String::from("Carlos"), 26);
let p = Person { name: String::from("Carlos"), age: 26 };
println!("{} {}", p.name, p.age);
View plus.c
#include <stdio.h>
/* Bitwise integer addition */
int plus(int x, int y)
{
int result = x ^ y;
int carry = (x & y) << 1;
if (carry != 0)
return plus(result, carry);
View bit_and.c
#include <stdio.h>
int bit_and(int x, int y)
{
return ~(~x | ~y);
}
int main(int argc, char **argv)
{
printf("%.8x\n", bit_and(6, 5));
View flatten.rb
def flatten(arr)
out = []
arr.each do |a|
if a.is_a?(Array)
out += flatten(a)
else
out << a
end
end
@carlosgaldino
carlosgaldino / gist:11023688
Created Apr 18, 2014
type inference in haskell
View gist:11023688
lengthOf x
| length x == 0 = "0"
| otherwise = length x
{--
lengthOf.hs:3:17:
Couldn't match expected type `[Char]' with actual type `Int'
In the return type of a call of `length'
In the expression: length x
In an equation for `lengthOf':
View keybase.md

Keybase proof

I hereby claim:

  • I am carlosgaldino on github.
  • I am carlosgaldino (https://keybase.io/carlosgaldino) on keybase.
  • I have a public key whose fingerprint is 761C C1E1 ED5E 9CE0 611D ECA8 24D3 CE8E 2906 1EF5

To claim this, I am signing this object:

@carlosgaldino
carlosgaldino / Gemfile
Last active Sep 27, 2016
Copy objects from multiple S3 buckets to another.
View Gemfile
source 'https://rubygems.org'
gem 'aws-sdk', '~> 1.30.1'
You can’t perform that action at this time.