Skip to content

Instantly share code, notes, and snippets.

View rawnly's full-sized avatar
🧨
fixing my printer

Federico rawnly

🧨
fixing my printer
View GitHub Profile
@rawnly
rawnly / template-engine.js
Created May 6, 2018 13:47
Simple nodejs template engine
function template(source, options = {}) {
const testers = {
replacer: /#\{\s?[\w]+\s?(\|\|\s?(\'|\")[\w]+(\'|\")\s?)?\}|\{\s?\{\s?[\w]+\s?(\|\|\s?(\'|\")[\w]+(\'|\")\s?)?\}\s?\}/gi,
alternative: /(\'|\")(.*)(\'|\")/i,
key: /#\{\s?([\w]+)\s?(\|\|\s?(\'|\")[\w]+(\'|\")\s?)?\}|\{\s?\{\s?([\w]+)\s?(\|\|\s?(\'|\")[\w]+(\'|\")\s?)?\}\s?\}/i,
doubleBrackets: /\{\{.*\}\}/g
};
return source.split("\n").map(row => {
const isRepleaceable = testers.replacer.test(row);
@rawnly
rawnly / nginx + node setup.md
Last active July 4, 2018 19:35 — forked from joemccann/nginx + node setup.md
Set up nginx as a reverse proxy to node.js.

The idea is to have nginx installed and node installed. I will extend this gist to include how to install those as well, but at the moment, the following assumes you have nginx 0.7.62 and node 0.2.3 installed on a Linux distro (I used Ubuntu).

In a nutshell,

  1. nginx is used to serve static files (css, js, images, etc.)
  2. node serves all the "dynamic" stuff.

So for example, www.foo.com request comes and your css, js, and images get served thru nginx while everything else (the request for say index.html or "/") gets served through node.

  1. nginx listens on port 80.
const { readFileSync: readFile } = require('fs');
const file = readFile('path-to-file', 'utf8');
const WPM = 300;
const wordSpeed = wpm => 60000 / wpm;
const readText = (txt, wpm) => {
const words = txt.split(/\s+/).map(item => item.trim().replace(',', ''))
let i = 0;
let int = setInterval(function() {
console.clear();
@rawnly
rawnly / clock.a.js
Last active July 16, 2018 12:49
Years of coding review
// Written 3y ago
(function( $ ) {
$.fn.newClock = function ( options ) {
var t, tNoMs, hexTime, element; // here we making this variables local to current jQuery object
function time() {
d = new Date();
day = {
@rawnly
rawnly / excuses.txt
Created August 24, 2018 19:38
All (literally) 145 sentences from developerexcuses.com
It was working in my head
Even though it doesn't work, how does it feel?
Oh, you said you DIDN'T want that to happen?
THIS can't be the source of THAT
I thought he knew the context of what I was talking about
I can have a look but there's a lot of if statements in that code!
It works, but it's not been tested
The accounting department must have cancelled that subscription
The marketing department made us put that there
I couldn't find any examples of how that can be done anywhere else in the project
const swapCase = (str) => str.split('').map(char => {
if ( char.toLowerCase() == char ) return char.toUpperCase()
if ( char.toUpperCase() == char ) return char.toLowerCase()
return char;
}).join('')
// Usage
@rawnly
rawnly / .zshrc
Created August 28, 2018 21:26
My DotFiles
# Path to your oh-my-zsh installation.
export ZSH=/Users/rawnly/.oh-my-zsh;
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
export SSH_KEY_PATH="~/.ssh/rsa_id";
export EDITOR='vim';
export CODE_FOLDER="~/code";
export NODE_ENV="devlopment";
# export PS1="$PS1 $(it2setkeylabel set status $(test -d .git && (git rev-parse --abbrev-ref HEAD || (echo -n 'Not a repo'))))"
@rawnly
rawnly / notification.swift
Created September 27, 2018 10:44
Notification in swift 4.2
// Notification in swift 4.2
// Tested on MacOS 10.14
func showNotification(title: String, body: String, icon: NSImage = nil) -> Void {
let notification = NSUserNotification()
notification.title = title
notification.subtitle = body
if ( icon !== nil ) {
@rawnly
rawnly / download_collections.py
Last active October 6, 2018 10:58
Download Unsplash Collections
import urllib2
import requests
import os
import json
import sys
# Local Lib
from utils import progress, dirExists, unsplashURL, getCollectionPhotos
# Container
const got = require('got');
const { JSDOM } = require('jsdom');
(async () => {
const { body } = await got("https://ttsl.pt/passageiros/horarios-de-ligacoes-fluviais/ligacao-barreiro-terreiro-do-paco/");
const { window: { document } } = new JSDOM(body);
const [t1, t2] = Array.from(document.getElementById('Dias úteis').children)
.filter(element => element.classList.contains('table-responsive'))