Skip to content

Instantly share code, notes, and snippets.

View altamic's full-sized avatar

Michelangelo Altamore altamic

View GitHub Profile
@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 / 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 / bitdump.sh
Created January 25, 2011 22:20
dumps Bitcoin network traffic
#!/usr/bin/env sh
# bitdump.sh
#
# captures Bitcoin network traffic
SELF=`basename $0`
if [[ $1 = "" ]]; then
DEFAULT="en1"
@altamic
altamic / block_chain.rb
Created August 26, 2011 14:46
Blockchain consisting of proof of work as from lian
#
# Ruby Example of the 'proof of work' explanation
# from https://en.bitcoin.it/wiki/Proof_of_work
#
# note: block data passed to do_work is simplified.
# bitcoin blockchain is more complex too.
#
require 'digest/sha2'
@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 / 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}/>"