Skip to content

Instantly share code, notes, and snippets.

View twitterFollowerCuratorBot.php
<?php
//
// AUTO KEYWORD-BASED FOLLOWER CURATION BOT (by @levelsio)
//
// https://gist.github.com/levelsio/6ee6c47283ee414ef3aace1d81986717
//
// File: twitterFollowerCuratorBot.php
//
// Created: May 2021
@marcaube
marcaube / .gitconfig
Created May 1, 2017 — forked from imkevinxu/.gitconfig
`git random` alias that will commit a random commit message from http://whatthecommit.com/
View .gitconfig
[alias]
random = !"git add -A; git commit -am \"$(echo $(curl -s http://whatthecommit.com/index.txt)\" (http://whatthecommit.com)\")\"; git pull --rebase; git push"
@marcaube
marcaube / harlem-shake.js
Created Apr 8, 2016
Harlem Shake, a script to make those XSS dance
View harlem-shake.js
// Source: http://pastebin.com/aJna4paJ
javascript:(function(){function c(){var e=document.createElement("link");e.setAttribute("type","text/css");e.setAttribute("rel","stylesheet");e.setAttribute("href",f);e.setAttribute("class",l);document.body.appendChild(e)}function h(){var e=document.getElementsByClassName(l);for(var t=0;t<e.length;t++){document.body.removeChild(e[t])}}function p(){var e=document.createElement("div");e.setAttribute("class",a);document.body.appendChild(e);setTimeout(function(){document.body.removeChild(e)},100)}function d(e){return{height:e.offsetHeight,width:e.offsetWidth}}function v(i){var s=d(i);return s.height>e&&s.height<n&&s.width>t&&s.width<r}function m(e){var t=e;var n=0;while(!!t){n+=t.offsetTop;t=t.offsetParent}return n}function g(){var e=document.documentElement;if(!!window.innerWidth){return window.innerHeight}else if(e&&!isNaN(e.clientHeight)){return e.clientHeight}return 0}function y(){if(window.pageYOffset){return window.pageYOffset}return Math.max(document.documentElement.
@marcaube
marcaube / entities-domain-and-models.md
Last active Feb 11, 2021
On Domain objects and code organization
View entities-domain-and-models.md

A few days – or was it weeks – ago, I answered hastily to a question on the Symfony2 Google Group. The question is simple but the answer is not : How do your organise your code in a Symfony project?

I've had some time to think about it and wanted to elaborate on the subject. Writing makes me think, and thinking is good.

Everyone has their own way to do this. Some organize their code in a way that makes them faster – like in the RAD edition. Some others take the time and put the emphasis on making things isolated, modular and re-usable. Most of us fall somewhere in the middle, still trying to find the structure that suits us, our workflow or our organization the most.

My original answer to the question was to keep the domain logic separate from the bundle code, i.e. place it in a re-usable library. The reason is that your business logic should be encapsulated into models, outside of persistance concerns, logging and al

@marcaube
marcaube / fa.sublime_snippet
Created Jul 18, 2017 — forked from calebporzio/fa.sublime_snippet
Font Awesome sublime snippet for creating icon tags
View fa.sublime_snippet
<snippet>
<content><![CDATA[
<i class="fa fa-fw fa-${1}"></i>&nbsp;
]]></content>
<tabTrigger>fa</tabTrigger>
<description>Font Awesome Icon</description>
<scope>text.blade, text.html.blade, text.html</scope>
</snippet>
@marcaube
marcaube / CastsValueObject.php
Created Jan 16, 2017 — forked from cmaas/CastsValueObject.php
A Trait to automatically cast value objects in Laravel without needing a Mutator and an Accessor.
View CastsValueObject.php
<?php
trait CastsValueObjects
{
protected function castAttribute($key, $value)
{
$castToClass = $this->getValueObjectCastType($key);
// no Value Object? simply pass this up to the parent
if (!$castToClass) {
return parent::castAttribute($key, $value);
@marcaube
marcaube / watchr_script.rb
Created Aug 28, 2013
Automatically generate styleguide with styledocco from less files with the watchr gem. Lauch with `$ watchr watchr_script.rb`
View watchr_script.rb
watch('(.*).less') do |match|
system("styledocco")
end
@marcaube
marcaube / blog-performance-et-pubs.md
Last active Dec 16, 2015
Performance web et publicités
View blog-performance-et-pubs.md

Préambule

Ces derniers temps, j'ai été confronté à un problème de performance sur le site d'un client. Le site est développé avec Symfony2, utilise l'ORM Doctrine2, il est responsive, utilise adaptive-images pour servir des images optimisées, etc etc.

Jusque là, le site avait été optimisé pour mettre en cache les requêtes à la base de données (Query & Result cache), mettre en cache des fragment de template (avec les ESI) et utiliser au mieux les entêtes HTTP pour mettre en cache les pages du côté client.

Les résultats de ces mises en cache granulaires était un temps de chargement entre 60ms pour une cache navigateur primée et ~150-200ms quand il y avait un hit sur l'application, parce que la plupart du temps il n'y avait aucun hit sur la base de données.

Le problème

Le problème est arrivé quand le client a décidé d'ajouter des publicités sur son site. Ne voulant pas utiliser un ad-network existant, le cl

@marcaube
marcaube / vendors
Created Sep 19, 2012 — forked from ubermuda/vendors.php
A symfony2 vendors script hacked to handle svn urls
View vendors
#!/usr/bin/env php
<?php
/*
* This file is part of the Symfony Standard Edition.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
@marcaube
marcaube / bootstrap-hugrid.js
Created Mar 26, 2012
Twitter Bootstrap Heads-Up Grid
View bootstrap-hugrid.js
definegrid = function() {
var browserWidth = $(window).width();
// LARGE DESKTOP & UP
if (browserWidth >= 1200)
{
pageUnits = 'px';
colUnits = 'px';
pagewidth = 1170;
columns = 12;