Skip to content

Instantly share code, notes, and snippets.

View darkmavis1980's full-sized avatar
🎯
Focusing

Alessio Michelini darkmavis1980

🎯
Focusing
View GitHub Profile
@darkmavis1980
darkmavis1980 / vscode-extensions.sh
Created November 14, 2019 13:45
Show installed VS Code plugins
code --list-extensions | xargs -L 1 echo code --install-extension
@darkmavis1980
darkmavis1980 / relative-to-absolute.js
Created November 12, 2019 11:51
Relative links to asbolute regex
const text = `
<p>This is some test with <a href=\"/piesync.html\">a relative link</a> and one with an <a href=\"http://piesync.com\">absolute link</a></p>
<p>This is some test with <a href=\"/piesync.html\" title="test">a relative link</a> and one with an <a href=\"http://www.piesync.com\">absolute link</a></p>
<p>This is some test with <a href=\"/piesync/hello/path\">a relative link</a> and one with an <a href=\"http://piesync.com\">absolute link</a></p>
<p>This is some test with <a href=\"/\">a relative link</a> and one with an <a href=\"http://piesync.com\">absolute link</a></p>
<p>This is some test with <a href=\"/?_ga=2.12323232.131232131.423413123-1231231.123123123\">a relative link</a> and one with an <a href=\"http://piesync.com\">absolute link</a></p>
`;
let replaced = text.replace(/<a href="(\/([\w.\/?=-]+)|\/)/gm, `<a href="https://www.domain.com$1`);
@darkmavis1980
darkmavis1980 / class.js
Created November 12, 2019 11:41
Function constructor vs class
// These are equals
class Test {
constructor(name) {
this.name = name;
}
getName() {
return this.name;
}
@darkmavis1980
darkmavis1980 / react-chartjs-2-mock
Created October 30, 2019 21:13
jest-react-chartjs-2
jest.mock('react-chartjs-2', () => ({
Pie: () => null,
}));
@darkmavis1980
darkmavis1980 / http.py
Created October 10, 2019 09:21
Run simple http server with python3
python -m http.server 8000
@darkmavis1980
darkmavis1980 / delete-git-branches
Created July 27, 2019 13:40
Delete all git branches matching regex
git branch | grep "<pattern>" | xargs git branch -D
@darkmavis1980
darkmavis1980 / recent.js
Created July 21, 2019 00:48
Mongodb: Show most recent events by a sub document
db.getCollection('competitions').aggregate([
{
$unwind: '$matches'
},
{
$sort: { 'matches.date': -1 }
},
{
$limit: 3
}
@darkmavis1980
darkmavis1980 / filter.js
Created July 19, 2019 10:47
mongo_aggregate_and_filter
/**
* This will filter down to the matches with a specific player, with the matches being played after a specific date,
* and it will show only the aggregate matches after that date ignoring the previous ones
*/
var dateFilter = new ISODate("2019-06-01T20:15:31Z");
db.getCollection('competitions').aggregate([
{
$match: {
players: ObjectId("5c71c4c1185c610046f17911"),
@darkmavis1980
darkmavis1980 / docker_root
Created March 20, 2019 13:56
Access as root to a container
docker exec -it -u root jenkins /bin/bash