Skip to content

Instantly share code, notes, and snippets.

@carlosgaldino
carlosgaldino / slope_vs_starting.md
Created April 8, 2023 10:51 — forked from gtallen1187/slope_vs_starting.md
A little bit of slope makes up for a lot of y-intercept

"A little bit of slope makes up for a lot of y-intercept"

01/13/2012. From a lecture by Professor John Ousterhout at Stanford, class CS140

Here's today's thought for the weekend. A little bit of slope makes up for a lot of Y-intercept.

[Laughter]

// 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);
@carlosgaldino
carlosgaldino / Gemfile
Last active September 27, 2016 02:18
Copy objects from multiple S3 buckets to another.
source 'https://rubygems.org'
gem 'aws-sdk', '~> 1.30.1'
// 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;
};
-module(msort).
-export([sort/1]).
sort([]) ->
[];
sort([X]) ->
[X];
sort(List) ->
{Xs, Ys} = split(List),
merge(sort(Xs), sort(Ys)).
@carlosgaldino
carlosgaldino / gist:6131391
Last active December 20, 2015 12:29
pause/resume growl
on alfred_script(q)
tell application "System Events"
set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell
if isRunning then
tell application id "com.Growl.GrowlHelperApp"
set paused to is paused
if (paused) then
resume
# Configure post-commit hook to take a photo
function gimage() {
cp ~/.post-commit-image .git/hooks/post-commit
}
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);
#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);
#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));