Skip to content

Instantly share code, notes, and snippets.

View felds's full-sized avatar
:shipit:

Luiz “Felds” Liscia felds

:shipit:
View GitHub Profile
@felds
felds / gist:3784624
Created September 25, 2012 21:39
Exemplo de uso do ICanHaz
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Teste icanhaz</title>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.1.1/css/bootstrap-combined.min.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="container">
@felds
felds / gist:5152637
Last active December 14, 2015 21:39
Exemplo de "list comprehension" em PHP
#!/usr/bin/env php
<?php
$a = range(0, 20);
$divisibleBy = 3;
// array_values: normalize the retuning indices
// array_filter: perform a select
$b = array_values(array_filter($a, function ($value) use ($divisibleBy) {
return (($value % $divisibleBy) == 0);
@felds
felds / gist:5254591
Created March 27, 2013 14:29
Listando tweets com CoffeeScript
#!/usr/bin/env coffee
http = require 'http'
user = 'felds'
count = 10
url = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=#{user}&count=#{count}"
http.get url, (response) ->
buffer = new Buffer 0
@felds
felds / example.aiml
Last active December 17, 2015 21:09
Exemplo de substituição de node aplicado em um AIML.
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0">
<template>
Começo do texto ”<srai>include</srai>” fim do texto.
</template>
</aiml>
@felds
felds / gist:6056221
Last active December 20, 2015 02:29
Convert anything to HTML entities (including unicodes.)
<?php
function everythingEntities($str, $pattern = '/./u')
{
return preg_replace_callback($pattern, function ($match) {
list(, $ord) = unpack('N', mb_convert_encoding($match[0], 'UCS-4BE', 'UTF-8'));
return sprintf('&#%s;', $ord);
}, $str);
}
<?php
/**
* @param string $dir The dir to be removed
*/
function deleteTempDir($dir)
{
return `rm -fr $dir`;
}
@felds
felds / gist:36e8e74de7889ea760ec
Created September 25, 2014 22:18
How to protect yourself against Shellshock bug with PHP
<?php
// unsecure execution
$bug = '"() { :;} ; echo vulnerable" bash -c "echo "';
passthru("env X=$bug"); // outputs: "vulnerable"
// secure execution using escapeshellarg
$bug = escapeshellarg('"() { :;} ; echo vulnerable" bash -c "echo "');
passthru("env X=$bug"); // what it should (the dump of env)
<?php
/**
* Usage:
* ms(12345, 3) # returns "37035"
* ms(999, 3) # returns "2997"
* ms("1111", 24) # returns "26664"
*
* @param int|stirng $s A string containing a positive integer
* @param int $m The multiplier
* @return string The product of the multiplication (as a string)
@felds
felds / SassMeister-input.scss
Created January 8, 2016 19:32
Generated by SassMeister.com.
// ----
// libsass (v3.3.2)
// ----
$silent-classes: true;
%card {
content: ".card definitions";
}
%card-header {
@felds
felds / gulpfile.js
Last active October 3, 2018 05:43
Error handling in Gulp using `gulp-plumber` and `gulp-notify`
const gulp = require('gulp');
const plumber = require('gulp-plumber');
const notify = require('gulp-notify');
const plumber_notifier = plumber({
errorHandler: notify.onError({
title: "Oops!",
message: "<%= error.message %>",
}),
});