Skip to content

Instantly share code, notes, and snippets.

var postcss = require('postcss');
module.exports = postcss.plugin('postcss-clean-var-backslash', function() {
return function (css) {
css.walkRules(function(rule) {
rule.selector = rule.selector.replace(/^\\--/, '--');
});
};
});
@ericsaboia
ericsaboia / fn.js
Created December 5, 2015 11:01 — forked from jescalan/fn.js
lazy-loading require in node
/**
* Requires a library, but only loads it when it's actually used.
*
* lazy_require('fs');
* fs.readFileSync('example.js');
*
* var wow = lazy_require('fs');
* wow.readFileSync('example.js');
*
* @param {String} lib - name of the lib you want to load
@ericsaboia
ericsaboia / iptables.sh
Created October 6, 2014 23:13
Iptables basic rule
sudo iptables -F # flush rules
sudo iptables -A INPUT -i eth0 -p tcp --dport 50000 -j ACCEPT # allow ssh
sudo iptables -A INPUT -i eth1 -j ACCEPT # allow everything on local network
sudo iptables -A INPUT -j DROP # drop everything else
@ericsaboia
ericsaboia / reactivate-jobtype.js
Created September 11, 2014 15:49
Reactivate kue jobs passing a type
var kue = require('kue');
var jobs = kue.createQueue();
console.log('Restarting job ' + process.argv[2]);
jobs.state(process.argv[2], function (err, ids) {
ids.forEach(reactivate);
});
function reactivate (id) {
sudo iptables -F
sudo iptables -X
sudo iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A INPUT -p icmp -j ACCEPT # allow ping
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT # allow SSH
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT # allow HTTP
sudo iptables -I INPUT -i lo -j ACCEPT # allow local
sudo iptables -A INPUT -j DROP # drop everything else
@ericsaboia
ericsaboia / youtube_search_example.js
Created May 21, 2014 22:09
Reproduces youtube-search fatal error
var youtubeSearch = require('youtube-search');
var keyword = 'Looney Tunes: De Volta à Ação filme trailer oficial';
youtubeSearch.search(keyword, {maxResults: 1}, function (err, youtube) {
console.log(err);
console.log(youtube);
});
@ericsaboia
ericsaboia / uncaughtException.js
Created May 19, 2014 15:11
Sending emails on uncaughtException
if (config.admin.email) {
process.on('uncaughtException', function(err) {
console.log(err.stack);
nodemailer.createTransport("SMTP", {
service: "Sendgrid"
, auth: {
user: config.smtp.username
, pass: config.smtp.password
}
}).sendMail({
@ericsaboia
ericsaboia / statesAndCapitals.json
Created April 15, 2014 19:02
Brazilian's states and capitals
[
{ "name": "Acre", "code": "AC", "capital": "Rio Branco" },
{ "name": "Alagoas", "code": "AL", "capital": "Maceió" },
{ "name": "Amazonas", "code": "AM", "capital": "Manaus" },
{ "name": "Amapá", "code": "AP", "capital": "Macapá" },
{ "name": "Bahia", "code": "BA", "capital": "Salvador" },
{ "name": "Ceará", "code": "CE", "capital": "Fortaleza" },
{ "name": "Distrito Federal", "code": "DF", "capital": "Brasília" },
{ "name": "Espírito Santo", "code": "ES", "capital": "Vitória" },
{ "name": "Goiás", "code": "GO", "capital": "Goiânia" },
@ericsaboia
ericsaboia / Makefile
Created January 31, 2014 13:31
Mocha Makefile
REPORTER = spec
check: test
test: test-unit
test-unit:
@NODE_ENV=test mocha \
--reporter $(REPORTER) \
test/configure.js test/models/*.js
@ericsaboia
ericsaboia / .bashrc_git
Last active December 25, 2015 19:29
Display Git Branch or Tag Names in your Bash Prompt
# Replace your PS1, inside ~/.bashrc for this:
# source ~/.bashrc_git
# PS1='\w\[\033[0;32m\]$(parse_git_branch_or_tag)\[\033[00m\]: '
parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
parse_git_tag () {
git describe --tags 2> /dev/null