Skip to content

Instantly share code, notes, and snippets.

View antoniopicone's full-sized avatar

Antonio Picone antoniopicone

View GitHub Profile
@antoniopicone
antoniopicone / Heap.js
Created September 4, 2016 16:52
A JS implementation of a Heap. HeapSort function also provided.
var Heap = function(input) {
this.arrayLength = input.length ;
for(var j= Math.floor(this.arrayLength / 2);j>=0; j--) {
this.heapify(input,j);
console.log(j);
}

Keybase proof

I hereby claim:

  • I am antoniopicone on github.
  • I am antoniopicone (https://keybase.io/antoniopicone) on keybase.
  • I have a public key ASAJ5jWz9KqkFfPTdFNu19S2fsxZuYA0ceUu8eizO8mYLwo

To claim this, I am signing this object:

var sequence = [3,4,1,2,6,5,8,7,9,0];
function insertionSort() {
for (var j=1;j<sequence.length;j++) {
var key = sequence[j];
var i=j-1;
while( i>=0 && sequence[i]>key ) {
sequence[i+1] = sequence[i];
i = i-1;
var merge = function(A,p,q,r) {
// 1, 4 , 9, intervalli da [1..4] incluso, [5...9]
var n1 = q - p +1; // = 4 -1 +1 = 4
var n2 = r - q; // 5
var L = [], R = [];
for(var i=1; i<=n1;i++) { // da 1 a 4
L[i] = A[p + i - 1]; // setta L[i] = A[1+1-1]= 6, L[1+2-1]=L[2]=7, L[1+3-1]=L[3]=8, L[1 + 4 -1]=L[4] = 9
}
for (var j=1;j<=n2;j++) { // da 1 a 5
// require Merge.js
var MergeSort = function(A,p,r) {
if (p < r) {
var q = Math.floor(r-p);
var left = MergeSort(A,p,q);
var right = MergeSort(A,q+1,r);
return Merge(A,p,q,r);
}
return A;
Array.prototype.swap = function(x,y) {
if(this[x] == undefined || this[y] == undefined) return;
var temp = this[x];
this[x] = this[y];
this[y] = temp;
};
Array.prototype.swap = function(x,y) {
if(x == undefined || y == undefined) return;
var temp = this[x];
this[x] = this[y];
this[y] = temp;
};
var Partition = function(A,p,r) {
var CountingSort = function(A,k) {
var B=[];
B.push(null); // avoid undefined
var C=[];
for (var i=0;i<=k;i++){
C[i] = 0;
}
for(var j=1;j<A.length;j++) {
@antoniopicone
antoniopicone / .Xmodmap
Last active August 21, 2019 13:40 — forked from bonndan/.Xmodmap
xmodmap config for Italian apple keyboard under ubuntu
! clean most of the modifiers
clear control
clear mod4
clear mod1
! gt, lt
keycode 49 = less greater less greater bar brokenbar bar
keycode 94 = backslash bar backslash brokenbar
! -----------------
@antoniopicone
antoniopicone / ubuntu_desktop_to_server.sh
Created April 17, 2020 17:10
Make an Ubuntu desktop setup more server friendly
#!/bin/bash
# Set runlevel 3 (disable gui)
sudo systemctl set-default multi-user.target
# Disable power management
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target