Skip to content

Instantly share code, notes, and snippets.

View fedecarg's full-sized avatar
🥄
There is no spoon

Federico Cargnelutti fedecarg

🥄
There is no spoon
View GitHub Profile

Extract links from a BBC responsive site

DOMAIN="m.bbc.co.uk"
SERVICE="hindi"
HTTP_USER_AGENT="Mozilla/5.0 (iPhone; Mobile; AppleWebKit; Safari)"
EXCLUDE_EXTENSIONS="\.\(txt\|css\|js\|png\|gif\|jpg\)$"
MAX_DEPTH="3"

wget --spider --no-directories --no-parent --force-html --recursive \

--level=$MAX_DEPTH --no-clobber \

Generate an HTML file from a Git patch

Installation:

$ brew install colordiff
$ brew install gnu-sed
$ wget http://www.pixelbeat.org/scripts/ansi2html.sh -O /tmp/ansi2html.sh && chmod +x /tmp/ansi2html.sh
@fedecarg
fedecarg / bbc_error_log_parser.sh
Last active September 16, 2016 10:22
BBC Error Log parser. Shows the most frequent error messages in an error.log file.
#!/bin/sh
# set unique $FILENAME
FILENAME=$(date +%d-%m-%y)-${APP_NAME}-${APP_ENV}
# set $LOG_URI (tail/download)
LOG_URI=https://bbc/logs/error_log/download/${APP_ENV}/error_log
# limit the $NUMBER_OF_LINES when processing large files (default: 4000 lines)
NUMBER_OF_LINES=${NUMBER_OF_LINES:=4000}
@fedecarg
fedecarg / vbox-guest-additions.sh
Last active January 27, 2020 11:53
GuestAdditions versions on your host (version) and guest (version) do not match
#
# How to update VirtualBox Guest Additions with vagrant
#
$ vagrant up
# Check the guest additions version:
$ vagrant vbguest --status
# If there's a version mismatch, you should see this message:
# [default] GuestAdditions versions on your host (x.x.x) and guest (x.x.x) do not match.
[
{
"media":{
"externalId":"p0475dm9",
"caption":"Rory Cellan-Jones asks if the iPhone 7 will return Apple's handset sales to growth",
"entityType":"Clip",
"id":{
"type":"videos",
"key":"primary",
"numericId":37303875
@fedecarg
fedecarg / node-mock-es6-import.js
Last active July 13, 2017 22:27
Mocking es6 imports in javascript unit tests
import {assert} from 'chai';
import sinon from 'sinon';
import mockRequire from 'mock-require';
describe('My module', () => {
let module; // module under test
let mocks;

Application architecture

To allow digital products to flourish we must provide a strong architectural foundation that supports high product quality, cost effective and time effective delivery and operational simplicity.

Application architecture seeks to build a bridge between business requirements and technical requirements by understanding use cases, and then finding ways to implement those use cases in the software. Good architecture reduces the business risks associated with building a technical solution. A good design is sufficiently flexible to be able to handle the natural drift that will occur over time in hardware and software technology, as well as in user scenarios and requirements.

Architectural styles

Modern tools and platforms help to simplify the task of building applications, but they do not replace the need to design your application carefully, based on your specific scenarios and requirements. The risks exposed by poor architecture include software that is unstable, is unable to sup

@fedecarg
fedecarg / load_script.js
Last active November 28, 2017 10:01
Load scripts asynchronously
const loadScript = (uri) => {
return new Promise((resolve, reject) => {
const el = document.createElement('script');
el.type = 'text/javascript';
el.src = uri;
if (id) {
const docEl = document.getElementById(id);
if (docEl) {
docEl.parentNode.removeChild(docEl);
@fedecarg
fedecarg / object_types.js
Last active June 12, 2018 08:57
Another way to type javascript objects
/**
* Checks the data type of property and throws a TypeError if it's invalid.
*
* Usage:
*
* function test(options = {}) {
* checkObjectTypes(options, {'a':'String', 'b':'Number', 'c':'Array'});
* }
*
* @param {Object} obj