Skip to content

Instantly share code, notes, and snippets.

View EdoardoVignati's full-sized avatar

Edoardo Vignati EdoardoVignati

View GitHub Profile
@EdoardoVignati
EdoardoVignati / git-clean.sh
Created March 9, 2021 10:55
Clean a Git environment from local changes and restore last commit
git checkout .
git clean -xdf
@EdoardoVignati
EdoardoVignati / access_to_lxc_container_file_system_from_host.sh
Created March 1, 2021 11:45
Access to lxc container file system from host
# List containers
lxc-ls -f -Fname,pid
# Get container pid
lxc-ls -f -Fpid mycontainer
# Access file system
cat /proc/containerpid/root/
@EdoardoVignati
EdoardoVignati / graph.pl
Created January 23, 2021 13:37
Minimal Ubuntu installation and working example of graph exploration with Prolog with DAG traversal and full console output
% sudo apt-get install software-properties-common
% sudo apt-add-repository ppa:swi-prolog/stable
% sudo apt-get update
% sudo apt-get install swi-prolog
edge(1,2)
edge(2,3)
edge(3,4)
edge(2,6)
edge(6,7)
@EdoardoVignati
EdoardoVignati / PS1 bash colours
Created November 19, 2020 18:15
PS1 bash colours
export PS1="\[\033[35m\]\t\[\033[m\]-\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "
@EdoardoVignati
EdoardoVignati / bootstrap-first-child-accordion.css
Created November 14, 2020 22:49
Bootsrap first child accordion add border
# Thanks to https://github.com/twbs/bootstrap/issues/27124#issuecomment-509009622
.accordion div.card:only-child {
border-bottom: 1px solid rgba(0, 0, 0, 0.125);
border-radius: calc(0.25rem - 1px);
}
@EdoardoVignati
EdoardoVignati / updates-rows.sql
Created November 2, 2020 18:51
Updates all rows based on a condition over the same table in MySql
UPDATE tbl
SET field_to_update = CASE
WHEN (SELECT COUNT(*) FROM (SELECT * FROM tbl) AS copy WHERE copy.field=<condition> HAVING COUNT(*)>0) THEN "this_value_if_true"
ELSE field_to_update
END
@EdoardoVignati
EdoardoVignati / time-interval.js
Last active October 6, 2020 14:48
Create a range of hours and minutes given start and end time in a day in Javascript
// Add to your html header
<script src="https://momentjs.com/downloads/moment.js"></script>
// Add these two functions
function buildInterval(start, end){
var range = [];
var time = moment.duration(start).asSeconds();
if(end<=start)
var endtime = moment.duration(end).asSeconds()+86400;
else
@EdoardoVignati
EdoardoVignati / click-and-longpress-in-jquery.js
Created September 28, 2020 22:41
Catch and distinguish between click and long press in jquery
<script>
//Checkout my improvement on StackOverflow: https://stackoverflow.com/a/34699164/6303265
var tmr = 0;
var islong = 0;
$(element).mousedown(function () {
tmr = setTimeout(function () {
// Handle the long-press
alert("You clicked for 1 second!");
console.log("You clicked for 1 second!");
islong=1;
@EdoardoVignati
EdoardoVignati / converter.py
Last active September 25, 2020 14:42
Convert 4 spaces to tab in a file (in particular in Python scripts)
#!/usr/bin/env python
import sys
line_buffer = []
if(len(sys.argv)<2):
print("Please provide a file path")
exit()
filepath = sys.argv[1]
@EdoardoVignati
EdoardoVignati / scrollable.dart
Last active September 17, 2020 11:44
Flutter Scaffhold with scrollable ListTiles with empty list check
@override
Widget build(BuildContext context) {
var i = 0;
var itemCount = 5;
return Scaffold(
appBar: AppBar(title: const Text('Scrollable list')),
body: itemCount > 0
? CustomScrollView(
shrinkWrap: true,