Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home... permanently!

Andrea Grandi andreagrandi

🏠
Working from home... permanently!
View GitHub Profile
@andreagrandi
andreagrandi / unmarshall_example.go
Created Aug 18, 2014
Example of Unmarshal (from JSON to struct) in Go
View unmarshall_example.go
package main
import (
"fmt"
"encoding/json"
)
type Message struct {
Name string
Body string
@andreagrandi
andreagrandi / read_config.go
Created Aug 21, 2014
Read values from a JSON configuration file
View read_config.go
// Parse a conf.json file with this content:
//
// {
// "username": "YourUser",
// "password": "YourPassword"
// }
package main
import (
@andreagrandi
andreagrandi / get_client.go
Created Aug 21, 2014
http.get() example to get a remote url and display its content
View get_client.go
package main
import (
"flag"
"fmt"
"io/ioutil"
"net/http"
)
var url = flag.String("u", "", "URL to read")
@andreagrandi
andreagrandi / text_file_reader.go
Created Aug 21, 2014
Read a text file and print its lines in Go
View text_file_reader.go
package main
import (
"flag"
"fmt"
"io/ioutil"
"strings"
)
var fileName = flag.String("f", "", "Filename to be read")
@andreagrandi
andreagrandi / insert_element_list.go
Last active Aug 29, 2015
How to insert an element at position i in an arrray of strings
View insert_element_list.go
package main
import (
"fmt"
)
func main() {
list_a := []string{"apple", "orange", "grapes"}
fmt.Println(list_a)
i := 1
@andreagrandi
andreagrandi / main.cf
Created Aug 31, 2014
Postfix configuration example for email forwarding
View main.cf
myhostname = andreagrandi.it
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
@andreagrandi
andreagrandi / ping_test.sh
Created Sep 5, 2014
Ping an ip and print a different message if it can be pinged or not
View ping_test.sh
keepalive_host='120.0.0.1'
ping -q -c1 $keepalive_host >> /dev/null
if [ "$?" -ne "0" ]; then
echo "Cannot ping!"
else
echo "PING!"
fi
View wifi_recover.sh
keepalive_host='192.168.0.1'
ping -q -c1 $keepalive_host >> /dev/null
if [ "$?" -ne "0" ]; then
echo "`date` WIFI DOWN" >> wifi_log.txt
ifdown wlan0
rmmod 8192cu
modprobe 8192cu
ifup wlan0
View keybase.md

Keybase proof

I hereby claim:

  • I am andreagrandi on github.
  • I am andreagrandi (https://keybase.io/andreagrandi) on keybase.
  • I have a public key whose fingerprint is 3268 D0FB 9B9F 6099 BC9B 76CC 9927 BB56 7051 C921

To claim this, I am signing this object:

View keybase.md

Keybase proof

I hereby claim:

  • I am andreagrandi on github.
  • I am andreagrandi (https://keybase.io/andreagrandi) on keybase.
  • I have a public key whose fingerprint is 7238 74F6 886D 5994 323F 1781 8CFB 47AD C384 F0CC

To claim this, I am signing this object: