Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Mauro Locatelli crivotz

🏠
Working from home
View GitHub Profile
View fetch.js
async function init() {
try {
let login = await fetch('http://xxx.xxx.xxx.xxx/api/login', {
method: 'POST',
body: JSON.stringify({login: 'user', password: 'password'}),
}).then(response => response.json());
let action = await fetch('http://xxx.xxx.xxx.xxx/api/action', {
method: 'GET',
headers: {'Authorization': login.token},
}).then(response => response.json());
@crivotz
crivotz / git.sh
Created Mar 25, 2020
Compile git
View git.sh
sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
cd git
make prefix=/usr/local all
sudo make prefix=/usr/local install
@crivotz
crivotz / i3-gaps.md
Last active Dec 18, 2020
i3-gaps install/update
View i3-gaps.md

Debian dependencies

sudo apt-get install gcc make dh-autoreconf libxcb-keysyms1-dev libpango1.0-dev libxcb-util0-dev xcb libxcb1-dev libxcb-icccm4-dev libyajl-dev libev-dev libxcb-xkb-dev libxcb-cursor-dev libxkbcommon-dev libxcb-xinerama0-dev libxkbcommon-x11-dev libstartup-notification0-dev libxcb-randr0-dev libxcb-xrm0 libxcb-xrm-dev libxcb-shape0 libxcb-shape0-dev
cd /usr/local/src

Clone the repository

git clone https://www.github.com/Airblader/i3 i3-gaps

@crivotz
crivotz / redis.md
Last active Jul 29, 2019
Redis installation on Debian Stretch
View redis.md
sudo apt-get install redis-server
sudo systemctl enable redis-server.service
sudo vim /etc/redis/redis.conf

set

maxmemory 256mb
maxmemory-policy allkeys-lru
View active_storage_example.rb
<% @post.uploads.each do |upload| %>
<% if upload.variable? %>
<%= link_to image_tag(upload.variant(resize: "400x400")), upload %>
<% elsif upload.previewable? %>
<%= link_to image_tag(upload.preview(resize: "400x400")), rails_blob_path(upload, disposition: :attachment) %>
<% elsif upload.image? %>
<%= link_to image_tag(upload, width: 400), upload %>
<% else %>
<%= link_to upload.filename, rails_blob_path(upload, disposition: :attachment) %>
<% end %>
@crivotz
crivotz / makerequest.js
Created Jan 8, 2019
Request with XMLHttpRequest and promises
View makerequest.js
function makeRequest(opts) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open(opts.method, opts.url);
xhr.withCredentials = true;
xhr.onload = function() {
if (this.status >= 200 && this.status < 300) {
resolve(xhr.response);
} else {
reject({
View rails_dirty.md

Rails dirty

After modifying an object and after saving to the database, or within after_save:

Rails <= 5 Rails >= 5.1
attribute_changed? saved_change_to_attribute?
changed? saved_changes?
changes saved_changes
attribute_was attribute_before_last_save
View Termite on Debian 9
sudo apt-get install -y \
git \
g++ \
libgtk-3-dev \
gtk-doc-tools \
gnutls-bin \
valac \
intltool \
libtool \
libpcre2-dev \
@crivotz
crivotz / vim_installation.md
Last active Jul 15, 2019
Vim installation
View vim_installation.md

Clean from standard vim

sudo apt-get remove --purge vim vim-runtime vim-gnome vim-tiny vim-common vim-gui-common

Vim dependency

sudo apt-get install liblua5.2-dev luajit libluajit-5.1 python3.7-dev ddddddpython-dev libperl-dev libncurses5-dev ruby-dev

if you want gVim add also this

View .remap_caps_lock.sh
#!/bin/sh
xmodmap ~/.Xmodmap