Skip to content

Instantly share code, notes, and snippets.

@mulatinho
mulatinho / mlt_read_code.php
Last active August 20, 2016 19:30
simple function to read code and print in pretty format
<?php
function mlt_valida_input($input) {
$pattern = '[^A-Za-z0-9.]';
return ereg($pattern, $input);
}
function mlt_read_code($input) {
if (mlt_valida_input($input))
return 1;
@mulatinho
mulatinho / gist:532f5f4d71a90ae6211f
Created February 12, 2015 02:28
hmm.. some regexp that i wrote late night
$buffer = preg_replace('/(http([^\s]+))/', '<a target="_blank" href="\\1">\\1</a>', $buffer);
$buffer = preg_replace('/(image:)([^\s]+)/',
'<img style="float: right; margin: 0px 0px 15px 15px; width: 150px;" src="\\2"/>', $buffer);
@mulatinho
mulatinho / ex_tdd_assert.c
Created February 15, 2015 02:11
simple example of using assert for tdd in c
#include <stdio.h>
#include <assert.h>
#define DEBUG(res) printf("\n%s in '%s' on function %s() line %d, tests_run: %d, tests_ok: %d, tests_fail: %d\n", \
res ? "success" : "fail", __FILE__, __func__, __LINE__, tests_run, tests_ok, (tests_run-tests_ok))
#define _assert(test) do { if (!(test)) { DEBUG(test); tests_run++; return 1; } \
DEBUG(test); tests_run++; tests_ok++; } while(0)
int tests_ok = 0;
int tests_run = 0;
# source /etc/profile.d/32dev.sh
# export ARCH=i486
# source *info; wget -c $DOWNLOAD; sh *SlackBuild
# installpkg /tmp/OpenAL-1.16.0-i486-1_SBo.tgz
class AreUFuknWithMe {
let rake = 0.26;
var total: Double = 0;
let bills: [Double] = [ 1, 1.87, 2, 4.3, 6.57 ];
init() {
var x = 0;
for (; x<4; x++) {
println("Duh")
@mulatinho
mulatinho / cpf.swift
Last active February 17, 2017 02:43
Validação de CPF no Swift
// algoritmo: res1 = sum(digits[0-9] * 10...2) % 11; res2 = sum(digits[0-10] * 11...2) % 11
// if (digit10 == res1 && digit11 && res2) { cpf valido }
func checkIfCPFisValid(obj: AnyObject?) -> Bool
{
var input: String = ""
if let object = obj as? UITextField {
input = object.text!
}
initial - representa o valor inicial investido;
interest - a taxa de rendimento médio mensal;
months - o número de meses em que o investimento será realizado;
$ initial=50000; interest=1.00961; months=60; for i in `seq 1 $months`; do initial=`echo "scale=2; $initial * $interest"|bc`; printf "month %2d, r$ %12.2f\n" $i $initial; done
month 1, r$ 50480.50
month 2, r$ 50965.62
month 3, r$ 51455.40
month 4, r$ 51949.88
month 5, r$ 52449.12
@mulatinho
mulatinho / challenge001.sh
Last active August 25, 2016 20:11
challenge001.sh
#!/bin/bash
# https://alex.mulatinho.net/2016/08/17/desafio-shell-script-001/
# Alexandre Mulatinho - http://alex.mulatinho.net - 20160820
#
# run tests:
# $ ( TESTES=$(( (RANDOM % 20) + 1 )); echo $TESTES; \
# for i in `seq 1 $TESTES`; \
# do N=$(( (RANDOM % 5) + 1 )) ; echo -n "$N "; \
# for x in `seq 1 $N`; do DIA=$(( (RANDOM % 31) + 1)); echo -n "$DIA "; done; \
# echo; done; echo $(( (RANDOM % 12) +1 )) ) | ./challenge001.sh
@mulatinho
mulatinho / s3upload.sh
Last active October 26, 2016 12:59
upload files to S3 using shell script
#!/bin/bash
# amazon s3 upload file code
# written by Alexandre Mulatinho < alex @ mulatinho . net >
# Wed Oct 26 09:30:54 BRT 2016
# use -> ./s3upload.sh hostAmazon yourBucketName yourFilename
[ ! "$3" ] && echo "use: $0 <host> <bucket> <file>" && exit 1
dateNow="`TZ=Africa/Bumako date "+%a, %0e %b %Y %T %z"`"
host="$1"
@mulatinho
mulatinho / uploadToS3.js
Last active April 25, 2017 19:41
uploading to amazon S3 without AWS-SDK or any other module but native
/* Upload to Amazon S3 without AWS-SDK or other modules
* Alexandre Mulatinho <alex at mulatinho.net> 2016
*
* You will need to change:
* - YOUR_FILENAME_HERE
* - YOUR_BUCKET_HERE
* - AWS_SECRET_KEY_HERE
* - AWS_ACCESS_KEY_HERE */
var https = require("https");