Skip to content

Instantly share code, notes, and snippets.

😎
Chillin'

Avaray Avaray

😎
Chillin'
Block or report user

Report or block Avaray

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View app.js
const request = function(url) {
return new Promise((resolve, reject) => {
const lib = url.startsWith('https') ? require('https') : require('http');
const request = lib.get(url, (response) => {
if (response.statusCode < 200 || response.statusCode > 299) {
reject(new Error('Failed to load page, status code: ' + response.statusCode));
}
const body = [];
response.on('data', (chunk) => body.push(chunk));
response.on('end', () => resolve(body.join('')));
@Avaray
Avaray / MagPi_Issues.sh
Last active Mar 20, 2019
[BASH] Download all MagPi Issues at once (sequentially) // Because official download page is not user friendly
View MagPi_Issues.sh
#!/bin/bash
TOTAL=$(curl -s "https://www.raspberrypi.org/magpi-issues/" | grep -Eo "\"MagPi[0-9]+.pdf" | wc -l)
for issue in $(eval echo {01..$TOTAL}); do
[ ! -f "MagPi$issue.pdf" ] && curl -Os "https://www.raspberrypi.org/magpi-issues/MagPi$issue.pdf"
done
@Avaray
Avaray / app.js
Last active Feb 24, 2019
[NodeJS] Puppeteer Starter // for API visit https://pptr.dev/
View app.js
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({headless: true})
var pages = await browser.pages()
var page = pages[0]
await page.goto('')
@Avaray
Avaray / rpi_update
Last active Mar 2, 2019
[BASH] Script for updating Raspberri Pi 3
View rpi_update
#!/bin/bash
dir="$(dirname "$(realpath "$0")")"
log="$(
date
sudo apt-get -y update
sudo apt-get -y upgrade
sudo rpi-update
sudo apt-get autoremove
@Avaray
Avaray / app.js
Created Jan 10, 2019
[NodeJS] Create HTTP server in simple way
View app.js
require('http')
.createServer()
.listen({
port: 4000
})
.on('request', (req, res) => {
res.end('Hello World!');
});
@Avaray
Avaray / app.js
Created May 11, 2018
[JS] Sort Keys in Object alphabetically
View app.js
let a = {};
Object.keys(b).sort().forEach(key => {
a[key] = b[key];
});
@Avaray
Avaray / app.js
Last active May 11, 2018
[JS] Delete empty Keys from Object
View app.js
function clean(o) {
Object.keys(o).forEach(k => (!o[k] && o[k] !== undefined) && delete o[k]);
return o;
}
@Avaray
Avaray / style.pug
Created Nov 2, 2017
Pug // Condition in CSS in .pug partial file // https://stackoverflow.com/a/41618071/4415165
View style.pug
style
.
.someclass1{
font-size:10px;
}
.someclass2{
font-size:10px;
}
if options.key1=='a'
.
@Avaray
Avaray / app.js
Last active Nov 1, 2017
Node JS // Get list of all directories (not recursive)
View app.js
var fs = require('fs')
var path = require('path')
var location = 'content'
fs.readdirSync(location)
.filter(x => {
return fs.lstatSync(path.join(location, x)).isDirectory()
})
.forEach(dir => {
@Avaray
Avaray / gist:8a6b8e2cf872edf49a1d5e2317d0ddde
Last active Feb 7, 2019
List of blogs with rating 100/100 in Google PageSpeed Insights.
View gist:8a6b8e2cf872edf49a1d5e2317d0ddde
// REAL BLOGS, ENTIRELY OPTIMISED
https://blog.fefe.de/
http://prog21.dadgum.com/
https://zupzup.org/
https://elliotec.com
https://www.tedunangst.com/flak/
http://rtfm.killfile.pl/
// OTHER BLOGS OR MOTIVATIONS YOU CAN CHECK
You can’t perform that action at this time.