Skip to content

Instantly share code, notes, and snippets.

Pierre Skowron pistou

Block or report user

Report or block pistou

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pistou
pistou / urlTransformation.js
Last active Dec 9, 2019
URL Parameters transformation
View urlTransformation.js
const objectToString = o => {
return Object.keys(o)
.map(k => `${encodeURIComponent(k)}=${encodeURIComponent(o[k])}`)
.join('&');
};
const obj = {foo: "bar", abc: "xyz", name: "John Doe"};
const str = objectToString(obj);
console.log(str); // foo=bar&abc=xyz&name=John%20Doe
@pistou
pistou / abstract.php
Last active Jul 13, 2016
Get N first characters of a string, without cutting off the last word
View abstract.php
<?php
$nbChars = 50;
$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus in ullamcorper est. Quisque semper commodo maximus. Pellentesque pharetra libero lorem, at scelerisque eros sollicitudin ac. Phasellus ullamcorper sem nisi, in tristique augue tincidunt eu. Vivamus congue at felis at porttitor. Curabitur eget urna ac arcu pharetra blandit. Etiam non facilisis ante. Proin iaculis consequat leo sit amet faucibus. Nulla sed venenatis nisl, eget placerat dolor. Donec aliquam egestas dui vitae faucibus. Quisque eget suscipit mauris. Vivamus eget sem erat.";
echo abstract($text, $nbChars);
function abstract(string $text="", int $nbChars=50) {
$abstract = explode("\n", wordwrap($text, $nbChars));
return $abstract[0] . " ...";
}
?>
You can’t perform that action at this time.