Skip to content

Instantly share code, notes, and snippets.

View cristianp6's full-sized avatar

Cristian Pascottini cristianp6

View GitHub Profile
@cristianp6
cristianp6 / bytes-conversion.js
Created March 25, 2021 06:29
Little helper containint bytes number to string label conversion and viceversa
const SIZES = ['B', 'KB', 'MB', 'GB', 'TB']
const bytesToSizeString = (bytes) => {
if (!+bytes || bytes < 0) {
return `0 ${SIZES[0]}`
}
const i = Math.floor(Math.log(bytes) / Math.log(1024))
return `${parseInt((bytes / Math.pow(1024, i)), 10)} ${SIZES[i]}`
}
@cristianp6
cristianp6 / state.ts
Last active August 23, 2019 14:11
Typed Meiosis with Function Patches and mithril-stream
import stream from 'mithril/stream'
import * as Stream from 'mithril/stream'
export type StatePatch<S> = (state: S) => S
export type AppState = {
step: string
}
export type AppActions = {
@cristianp6
cristianp6 / factory-function-pattern.md
Last active May 26, 2019 10:28
Make Factories not Classes

For the KISS principle, you can opt for the factory function pattern (aka closures) instead of using classes.

// Typings definition (stripped out at complie time):
type MyObject = {
  readonly aPublicMethod: () => void;
  readonly anotherPublicMethod: (anArgument: any) => any;
};

type MyObjectFactory = (aDependencyInstance: any, anotherDependencyInstance: any) => MyObject;
@cristianp6
cristianp6 / .gitconfig
Created May 19, 2017 10:43
My git config with handy custom aliases
[user]
name = Cris
email = cris@email.com
[alias]
# move into existing branch
co = checkout
# move into current development brach: change branch name
cod = checkout develop
# create new branch and move into it
cob = checkout -b
@cristianp6
cristianp6 / postgresql_changes_tracking.sql
Last active August 9, 2022 04:28
Log row changes in PostgreSQL - Any advice/improvement is welcome ;-)
/**
* Creates a "logging" schema with an "history" table where are stored records in JSON format
*
* Requires PostgreSQL >= 9.3 since data is stored in JSON format
*
* Credits: http://www.cybertec.at/2013/12/tracking-changes-in-postgresql/
*/
/* Create a schema dedicated to logs */
CREATE SCHEMA logging;
@cristianp6
cristianp6 / gist:cb40feca4266fa59faed
Last active August 29, 2015 14:14
Check URL HTTP headers response like Googlebot agent
# Detailed answer
curl -s -A "Googlebot/2.1 (+http://www.google.com/bot.html)" -D - YOUR_URL -o /dev/null
# Short answer
curl -sL -A "Googlebot/2.1 (+http://www.google.com/bot.html)" -w "%{http_code} %{url_effective}\\n" "YOUR_URL" -o /dev/null
# Other crawlers: http://www.useragentstring.com/pages/Crawlerlist/
@cristianp6
cristianp6 / SSHloginPasswordless.md
Last active October 26, 2016 08:41
SSH Passwordless auto login to remote host

Create authentication SSH-Kegen key on local/client host

cd ~ && ssh-keygen -t rsa

You could skip passphrase.

From host1, create .ssh directory on remote host via ssh

@cristianp6
cristianp6 / wpBlockSpamComments.php
Last active November 16, 2016 04:17
WordPress Block Spam Comments: no plugin, no dependencies, pure JavaScript, place in your functions.php
<?php
/* Block Spam Comments - BEGIN */
/* source: http://davidwalsh.name/wordpress-comment-spam */
add_action( 'wp_footer', 'catch_new_comment_submit' );
add_filter( 'preprocess_comment', 'preprocess_new_comment' );
function catch_new_comment_submit(){
global $post;
if( comments_open( $post->ID ) && (is_single() || is_page()) ){ ?>
<script type="text/javascript">
window.onload = function() { 'use strict';
@cristianp6
cristianp6 / Fetch email in a file.md
Last active April 29, 2020 10:26
Write retrieved emails on a log file (Ubuntu/Debian)

Write retrieved emails in a file

As root, install fetchmail

$ apt-get install fetchmail

Check if fetchmail has SSL support: if you see something like "libssl.so.0" then yours has it

$ ldd /usr/bin/fetchmail
@cristianp6
cristianp6 / geary.ini
Created January 17, 2014 19:05
Tophost.it IMAP/POP and SMTP configuration settings for send and receive emails through Geary email client (tested on Elementary OS 0.2 Luna): 1) open Geary and configure a new Account for your email.account@yourdomain.tld. Save and close Geary. 2) Edit the file geary.ini with a text editor: $ scratch-text-editor ~/.local/share/geary/email.accou…
[AccountInformation]
real_name=Your Real Name
nickname=Account name
service_provider=OTHER
ordinal=0
imap_username=tophost.username
imap_remember_password=true
smtp_remember_password=true
prefetch_period_days=14
imap_host=pop.yourdomain.tld