Skip to content

Instantly share code, notes, and snippets.

View esdrasbeleza's full-sized avatar

Esdras Beleza esdrasbeleza

View GitHub Profile
func (c LightestOperation) Result(images []containers.ImageContainer) (image.Image, error) {
if len(images) == 0 {
return nil, nil
} else if len(images) == 1 {
return images[0].GetImage(), nil
}
firstImage := images[0].GetImage()
bounds := firstImage.Bounds()
lightest := image.NewRGBA(image.Rect(0, 0, bounds.Dx(), bounds.Dy()))
type ImageContainer interface {
GetImage() image.Image
}
type FileImageContainer struct {
Filename string
}
func (f FileImageContainer) GetImage() image.Image {
file, _ := os.Open(f.filename)
@esdrasbeleza
esdrasbeleza / lightest1.go
Last active August 29, 2015 14:20
First version of Lightest operation
func (c LightestOperation) Result(images []image.Image) (image.Image, error) {
firstImage := images[0]
bounds := firstImage.Bounds()
lightest := image.NewRGBA(image.Rect(0, 0, bounds.Dx(), bounds.Dy()))
draw.Draw(lightest, bounds, firstImage, bounds.Min, draw.Src)
for _, currentImage := range images {
if currentImage.Bounds() != bounds {
return nil, errors.New("The images have different size!")
}
@esdrasbeleza
esdrasbeleza / lightest_excerpt.go
Last active August 29, 2015 14:20
lightest() function
func (c LightestOperation) lightest(color1, color2 color.RGBA) color.Color {
if c.luminance(color1) > c.luminance(color2) {
return color1
} else {
return color2
}
}
func (c LightestOperation) luminance(someColor color.Color) uint32 {
r, g, b, _ := someColor.RGBA()
@esdrasbeleza
esdrasbeleza / Preferences.sublime-settings
Last active August 29, 2015 14:14
Sublime configuration
{
"bold_folder_labels": true,
"fade_fold_buttons": false,
"font_face": "Fira Mono",
"font_size": 12,
"highlight_line": true,
"highlight_modified_tabs": true,
"ignored_packages":
[
"Vintage"
@esdrasbeleza
esdrasbeleza / check_connection.sh
Last active December 12, 2015 05:38
A script to verify if my connection is up and running. Put it to run in your crontab and you can have logs of your broadband internet connection, for example. Call $ check_connection.sh > output.log
#!/bin/sh
datetime=`date +%Y-%m-%d\ %H:%M:%S`
my_ip=`curl -s ifconfig.me`
exit_code=$?
if [ $exit_code == 0 ]; then
echo $datetime [ONLINE] $my_ip
else
echo $datetime [OFFLINE] Exit code: $exit_code