Skip to content

Instantly share code, notes, and snippets.

View Bebbolus's full-sized avatar

Roberto Bebbolus

View GitHub Profile
@Bebbolus
Bebbolus / main.php
Created May 26, 2017 21:13
non async PHP program example
<?php
$numbers = [7, 4];
foreach($numbers as $number)
{
if (isPrime($number))
{
echo “$number is a prime number!\n”;
}else {
echo “$number is a not prime number…\n”;
}
@Bebbolus
Bebbolus / isPrime.php
Last active May 26, 2017 21:29
non async PHP program example, Check if number is prime
<?php
function isPrime($numberToCheck) {
for($n = $numberToCheck- 1; $n > 1; $n--) {
if (!($numberToCheck% $n)) {
return false;
}
}
return true;
}
@Bebbolus
Bebbolus / generators.php
Created May 26, 2017 21:32
async PHP with generators
<?php
function isPrime($numberToCheck) {
for($i=0, $n=$numberToCheck-1; $n>1; $n--, $i++) {
yield $i;
if (!($numberToCheck % $n)) {
return false;
}
}
return true;
}
@Bebbolus
Bebbolus / first.go
Last active November 30, 2018 16:38
package main
import "fmt"
func Talk() {
fmt.Println("Hello FROM PLUGIN!!!")
}
var chain []middleware //empty chain
func main() {
chain = append(chain, pass("GET|POST"))
http.HandleFunc("/", Chain(controller, chain...))
log.Fatal(http.ListenAndServe(":8080", nil))
}
func pass(args string) func(http.HandlerFunc) http.HandlerFunc {
return func(f http.HandlerFunc) http.HandlerFunc {
// Define the http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
//split args and check if the request as this method
acceptedMethods := strings.Split(args, "|")
for _, v := range acceptedMethods {
if r.Method == v {
// Call the next middleware in chain
f(w, r)
func Chain(f http.HandlerFunc, mids ...middleware) http.HandlerFunc {
for _, m := range mids {
f = m(f)
}
return f
}
// middleware filter incoming HTTP requests.
// if the request pass the filter, it calls the next HTTP handler.
type middleware func(http.HandlerFunc) http.HandlerFunc
package main
import (
"fmt"
"log"
"net/http"
)
func controller(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there!")
package main
import (
"os"
"fmt"
"plugin"
)
func main() {
//open plugin file
plug, err := plugin.Open("plugins/first.so")
if err != nil {