Skip to content

Instantly share code, notes, and snippets.

Avatar
💚

pooya parsa pi0

💚
View GitHub Profile
@pi0
pi0 / Core files
Created Apr 19, 2015
Google translate Offline Language Files
View Core files
https://dl.google.com/translate/offline/v3/r1/c.zip
https://dl.google.com/translate/offline/v3/r1/profiles.txt
@pi0
pi0 / hrtime.js
Last active Nov 15, 2020
process.hrtime polyfill
View hrtime.js
(function() {
const nowOffset = Date.now();
const now = () => Date.now() - nowOffset;
global.process.hrtime = global.process.hrtime || ((previousTimestamp) => {
const baseNow = Math.floor((Date.now() - now()) * 1e-3)
const clocktime = now() * 1e-3
let seconds = Math.floor(clocktime) + baseNow
let nanoseconds = Math.floor((clocktime % 1) * 1e9)
if (previousTimestamp) {
@pi0
pi0 / README.md
Last active Nov 11, 2020
Nuxt Unattended Config Injection
View README.md

Nuxt loads configuration from several places and merges. Here is the order: (first has more periority)

  • Config overrides by CLI
  • nuxt.config (format: CJS/MJS/TS can be also wrapped into an async function)
  • .nuxtrc
  • ~/.nuxtrc

In order to automatically inject some configuration without direct modification of nuxt.config, it is possible to use .nuxtrc file.

Thanks to super simpler syntax of rc9 this configuration can be injected via a shell script or package itself.

@pi0
pi0 / README.md
Last active Nov 10, 2020
doNotTrack polyFill
View README.md

Tiny (230 char) Polyfill for window.doNotTrack. Checks for:

  • window.doNotTrack == 1
  • navigator.doNotTrack == 'yes'
  • navigator.doNotTrack == 1
  • navigator.msDoNotTrack == 1'
  • window.external.msTrackingProtectionEnabled()

And sets value to either 1 (do not track) or 0 (track)

View gist:0d55194d6c8415f5d8b9b7050fe76bf3
const fs = require('fs')
const axios = require('axios')
callback
fs.readFile('test.txt', 'utf-8', (err, str) => {
if (err) {
console.error('Something bad!' + err)
}
console.log(str)
})
@pi0
pi0 / cms.vue
Last active Aug 20, 2020
Vue Universal Runtime Compile
View cms.vue
<template>
<div>
<component :is="CMSComponent" :x="x" />
<button @click="x++">
Click on me
</button>
</div>
</template>
<script>
View ssh-proxy.sh
ssh -vo ProxyCommand='ssh -W %h:%p root@proxy_host' root@dst_host
@pi0
pi0 / pagespeed_nginx_ubuntu.sh
Last active Jul 30, 2020
Install PageSpeed on Ubuntu Nginx Extras
View pagespeed_nginx_ubuntu.sh
# Deps
sed -i "s|# deb-src|deb-src|" /etc/apt/sources.list
apt update
export DEPS=" \
build-essential zlib1g-dev libpcre3-dev unzip uuid-dev \
debhelper po-debconf libexpat-dev libgd-dev libgeoip-dev libhiredis-dev \
libluajit-5.1-dev libmhash-dev libpam0g-dev libperl-dev libssl-dev libxslt1-dev quilt"
apt install -y $DEPS
# NXG Pagespeed
View CKEditor.vue
<!-- Based on https://github.com/dangvanthanh/vue-ckeditor -->
<template>
<div class="ckeditor">
<textarea :id="id" :value="value"></textarea>
</div>
</template>
<style scoped>
.ckeditor {
@pi0
pi0 / colors
Last active May 11, 2020
Super Simple Node.js String Colors Support
View colors
This snippets add super Simple Node.js String Colors Support.
See here:
http://stackoverflow.com/questions/32474241/node-js-terminal-color
http://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color