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 / utils.php
Created September 7, 2016 20:58
Wordpress Utils
<?php
/**
* Return `true` if any of the items evals to `true`, `false` otherwise
*
* @param Array $list The list to be evaluated
* @return bool
*/
function all($list)
{
<?php
session_start();
if ($_COOKIE['current_cookie'] != $_SESSION['prev']) {
die("DENIED");
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Lightslider</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/lightslider/1.1.5/css/lightslider.min.css" rel="stylesheet" />
<style>
.container {
margin: 2rem auto;
@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 %>",
}),
});
@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 {
<?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 / 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
/**
* @param string $dir The dir to be removed
*/
function deleteTempDir($dir)
{
return `rm -fr $dir`;
}
@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);
}
@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>