Skip to content

Instantly share code, notes, and snippets.

View FernandoBasso's full-sized avatar

Fernando Basso FernandoBasso

View GitHub Profile
@FernandoBasso
FernandoBasso / ex-1-20-detab.c
Last active December 31, 2016 11:18
The C Programming Language, exercise 1-20 (DETAB input).
// Exercise 1-20. Write a program detab that replaces tabs in the input with
// the proper number of blanks to space to the next tab stop. Assume a fixed
// set of tab stops, say every n columns. Should n be a variable or a symbolic
// parameter?
// $ gcc -std=c99 -Wall -pedantic -L./lib -o devel devel.c -lmyline
// $ LD_LIBRARY_PATH=./lib ./devel <<< $'Li\tnu\tx\t\t!'
// len 39, line Li--------nu--------x----------------!
@FernandoBasso
FernandoBasso / input-example.c
Last active January 21, 2017 13:06
Exercice 1-23 from K&R book.
// Exercise 1-23. Write a program to remove all comments from a C program.
// Don't forget to handle quoted strings and character constants properly. C
// comments don't nest.
#include <stdio.h> // Includes the standard INPUT/OUTPUT library.
#include "lib/helpers.h" /* Includes our own helper functions. */
int main(void)
{
printf(/* cmt1 */"%d" /* cmt2 */ "\n", 10); /*
@FernandoBasso
FernandoBasso / bst-lookup-path.rkt
Created March 13, 2017 12:01
Binary Search Tree - lookup and path (in racket)
#lang htdp/bsl
;
; Invariants
; ----------
; at each level:
; - all accounts in left sub-tree have account number
; less than root;
; - all accounts in right sub-tree have account number
; greater than root;
@FernandoBasso
FernandoBasso / query.sql
Last active April 11, 2017 17:31
Categories and Subcategories (MariaDB)
DESCRIBE categorias;
SELECT CONCAT (
t1.nome
, IFNULL (CONCAT (' → ', t2.nome), '')
, IFNULL (CONCAT (' → ', t3.nome), '')
, IFNULL (CONCAT (' → ', t4.nome), '')
) AS fullpath
FROM categorias AS t1
LEFT JOIN categorias AS t2 ON t2.parent_id = t1.id
@FernandoBasso
FernandoBasso / App.vue
Created July 1, 2017 13:44
App Vue + TypeScript problem...
<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
@Component({
// Renders just “title: ”...
template: '<div>title: {{ theTitle }}</div>'
})
export default class App extends Vue {
private _title: string;
@FernandoBasso
FernandoBasso / lists.rkt
Created July 14, 2017 22:45
Produce lists in increasing number of items from input list.
(define (defsep los)
(if (empty? (rest los))
""
", "))
(define (concat los)
(cond [(empty? los) ""]
[else
(string-append (first los)
@FernandoBasso
FernandoBasso / combine-trees-abstractions.rkt
Created September 16, 2017 13:21
Exercise from EDX course How to Code.
;; #lang htdp/isl
(require 2htdp/image)
(define-struct dir (name sub-dirs images))
;; Dir is (make-dir String ListOfDir ListOfImage)
;; interp. An directory in the organizer, with a name, a list
;; of sub-dirs and a list of images.
(define I1 (square 10 "solid" "red"))
(define I2 (square 12 "solid" "green"))
In this problem we want you to design a function that produces all
possible filled boards that are reachable from the current board.
In actual tic-tac-toe, O and X alternate playing. For this problem
you can disregard that. You can also assume that the players keep
placing Xs and Os after someone has won. This means that boards that
are completely filled with X, for example, are valid.
NOTE: It was said that there would be 512 possible filled in boards
following the description above.
@FernandoBasso
FernandoBasso / tic-tac-toe-possible-boards.rkt
Last active October 17, 2017 12:51
Find possible board combinations
#lang htdp/isl+
;; Fetches `list-ref`, `take` and `drop`.
(require racket/list)
; PROBLEM 2:
;
; Below you will find some data definitions for a tic-tac-toe solver.
;
; In this problem we want you to design a function that produces all
; possible filled boards that are reachable from the current board.
@FernandoBasso
FernandoBasso / Admin.php
Last active October 15, 2017 16:34
catch not catching ...
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
<?php
class Admin