Skip to content

Instantly share code, notes, and snippets.

View trodrigues's full-sized avatar
😸
:3

Tiago Rodrigues trodrigues

😸
:3
View GitHub Profile
@trodrigues
trodrigues / refactoring_css.md
Created November 22, 2016 11:47
Refactoring CSS

After reading this tweet I thought I'd write some thoughts on why I disagree with the idea that CSS is unrefactorable.

I've done this before. I've taken a huge app, with a fairly complicated Jenga tower of CSS using lots of SASS nesting and turned it into something clean and maintainable. It took time, it was difficult and it took lots of discipline, but it's doable. And yeah, this probably won't always work, but here's the approach I took.

  • Start by defining guidelines and a class naming system
    • How to structure files, what methodology you're using. Doesn't really matter which, but pick one.
    • Every time a new use case comes along where people are not sure how to apply the methodology, talk about it and document it as a use case
  • Have a styleguide
    • Helps maintain visual consistency
  • Helps with people not reinventing things all the time (sometimes it has to be done though)
@trodrigues
trodrigues / twitlistmanager_labels.js
Created March 6, 2016 13:11
Bookmarklet for twitlistmanager.com which places labels for lists next to each checkbox
// Bookmark twitlistmanager.com on your browser, then edit the URL and replace with the line below
javascript:(function (){ var titles = []; function doCol(colType) { $(colType).each(function(idx, item){ $(item).find('td').each(function(idxCol, col) { if(idxCol>1) { var html = col.innerHTML; col.innerHTML='<label for="'+$(col).find('input').attr('id')+'">'+ html +titles[idxCol-2]+'</label>'; } }); }); } $('tr.title .columnHead img').each(function(idx, item){ titles.push(item.getAttribute('src').split('=')[1]); }); doCol('.lightYellow');doCol('.rowData');})();
// webpack.config.js
module.exports = {
entry: {
main: [
'./bootstrap.js'
]
},
output: {
path: __dirname,
filename: '[name].bundle.js'
@trodrigues
trodrigues / gist:173239e316afb91ac81f
Created May 28, 2015 09:42
timing reporter for jasmine
var timingReporter = {
suites: [{
id: 'root',
description: 'Entire Suite',
children: []
}],
getCurrentSuite: function () {
return _.last(this.suites);
@trodrigues
trodrigues / gist:6cbe73943baae57e2e2a
Created April 6, 2015 16:24
Mocking all sorts of stuff in angular (assumes lodash exists)
var mocks = angular.module('yourapp/mocks', []);
mocks.config(['$provide', '$controllerProvider', function ($provide, $controllerProvider) {
$provide.stubDirective = function (name, definition) {
$provide.factory(name + 'Directive', function () {
return [_.extend({
name: name,
restrict: 'A',
priority: 0,
}, definition)];
@trodrigues
trodrigues / gist:3a575d78e552cec785e6
Created March 11, 2015 16:18
Flux implementations
Fluxxor
Tuxedo
nexus-flux
Marty
Reflux
Fluxy
@trodrigues
trodrigues / gist:3220a4a3ed110f3b30cd
Created February 9, 2015 19:45
Running docker on a file watcher
/* Dockerfile */
FROM nodesource/node:trusty
COPY . /src
WORKDIR /src
VOLUME .:/src
RUN npm install -g watchy
RUN npm install
/* Build it */
docker build -t sdm_client .
@trodrigues
trodrigues / gist:4aead044ab1a81f1cf02
Created December 5, 2014 13:45
Deep object diff matcher for Jasmine 2
// use with https://www.npmjs.org/package/deep-diff
toEqualObj: function () {
var KINDS = {
'N': 'newly added property/element',
'D': 'property/element was deleted',
'E': 'property/element was edited',
'A': 'change occurred within an array'
};
@trodrigues
trodrigues / gist:f7cf379e5dd9ebf89cc1
Created September 26, 2014 16:46
commonjs and file loading

Loading a remote file through commonjs wouldn't be possible because commonjs is just the module format, not exactly a file loader. Require.js for instance is both: it's an implementation of the AMD module format AND a file loader. browserify for instance is just an implementation of the commonjs module format.

So you'd have to load the file separately, and when it's ready you could require it.

Let's say you have remote_module.js which goes:

exports.module = function(){};

and then somewhere else you'd have to do something like

for i in `find sourcefolder -name "config"|grep ".git/config"` ; do
echo "[user]" >> $i
echo "\tname = First Last" >> $i
echo "\temail = [email protected]" >> $i
done