Skip to content

Instantly share code, notes, and snippets.

View altamic's full-sized avatar

Michelangelo Altamore altamic

View GitHub Profile
@altamic
altamic / adb-wifi.zsh
Last active June 22, 2021 09:44
Activate adb wifi connecting to a LAN device by IP
# activate adb wifi connecting to a LAN device by IP
function adb-wifi {
if [ -z "$1" ]
then
echo "Usage:\nadb-wifi <device-ip>"
return 1
fi
ADB_WIFI_TCP_PORT=5555
adb tcpip $ADB_WIFI_TCP_PORT
adb connect "$1":$ADB_WIFI_TCP_PORT
@altamic
altamic / StateMachine.swift
Last active December 27, 2023 08:00
StateMachine in Swift
//
// StateMachine.swift
//
// Created by Michelangelo Altamore on 12/04/2018.
// Copyright © 2018 Michelangelo Altamore. All rights reserved.
//
import Foundation
protocol StateMachineInternals: class {
@altamic
altamic / private_access.cpp
Last active November 8, 2023 13:14
How to access to private members and methods of a C++ class
#include <iostream>
// This is a rewrite of the technique showed here:
// http://bloglitb.blogspot.com/2010/07/access-to-private-members-thats-easy.html
// https://gist.github.com/dabrahams/1528856
// Generate a static data member of type Stub::type in which to store
// the address of a private member. It is crucial that Stub does not
// depend on the /value/ of the the stored address in any way so that
// we can access it from ordinary code without directly touching
@altamic
altamic / keybase.md
Created February 2, 2017 18:56
keybase.io

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

@altamic
altamic / wc.rb
Created April 6, 2016 19:22
wc -l in Ruby
#!/usr/bin/env ruby
# Example implementation of wc -l
(ARGV.length == 0 ?
[["", STDIN]] :
ARGV.lazy.map { |file_name|
[file_name, File.open(file_name)]
})
.map { |file_name, file|
@altamic
altamic / gist:452b3ed9b6cc19db22b7
Created June 26, 2015 11:58
ruby http static server
# run an ad hoc http static server in your current directory (nobu)
ruby -run -ehttpd . -p8000
@altamic
altamic / bitcoin.md
Created September 29, 2014 20:17
p2p crypto currencies versus traditional financial institutions

P2P payments for the masses

In 2009 Satoshi Nakamoto conceived Bitcoin, an electronic payment system based on cryptographic proof instead of trust. Bitcoin allow to make payments over a communications channel without a trusted party. In this post I will try to explain why its design choices are sound and fair.

Fixed money stock

Unless you are living on mars, you cannot avoid the amount of bad economic news on mainstream media, i.e. governments promoting either banks bailouts or bankrupt corporations too big to fail, hence running on larger and larger deficits, incresing taxes while cutting to the bone their services to population.

We are turned into thinking that the only way to escape our doomsday scenario is creating money i.e. a money expansion.

@altamic
altamic / golden_rule_for_software_development.md
Last active December 24, 2015 09:49
Golden Rule for Software Development

Never deliver code liable to exploit the well-being of colleagues

What you can do

If you agree with the above principle, you are encouraged to adopt measures so that a such conduct can be effectively applied in your environment.

If you are a developer, be ready to point out (perhaps in writing) that you are willing to take full responsibility of your code and for this reason you are expected in some situation (i.e. insufficient technical experience, insufficient aptitude, etc.) to proclaim the impossibility to deliver code for ethical reasons conflicting with the principle. Reciprocally, you should have the right to know the position of each member of your team about the principle.

@altamic
altamic / array.js
Created November 2, 2012 13:48
javascript simple Array to Object conversion
> Array.prototype.toObject = function() {b={}; for(i=0;i<this.length;i+=2) {b[this[i]]=this[i+1]}; return b;}
[Function]
> ["chiave1","valore1","chiave2","valore2"].toObject()
{ chiave1: 'valore1', chiave2: 'valore2' }
@altamic
altamic / test_hash.rb
Created October 25, 2012 15:38
Hash structure for xml conversion
class Hash
def to_xml
case keys.size
when 0
""
when 1
result = nil
each_pair do |k, v|
case v
when nil then result = "<#{k.to_s}/>"