Skip to content

Instantly share code, notes, and snippets.

View unnikked's full-sized avatar
🏠
Working from home

Nicola Malizia unnikked

🏠
Working from home
View GitHub Profile
@unnikked
unnikked / EchoClient.java
Last active August 29, 2015 13:57
An EchoService example written in Java to explain the basic concept of Java Networking APIs using a TCP connection.
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
/**
* Classe client che si interfaccia con EchoServer. Un client
* può effettuare una sola richiesta del servizio per connessione.
*/
@unnikked
unnikked / installfont.sh
Created June 2, 2014 13:04
A simple bash script to install fonts on your Ubuntu like distro
#!/bin/bash
if [ $# -ne 1 ]; then
echo "USAGE: $0 [font-file]"
exit 1
fi
if [ "$(whoami)" != "root" ]; then
echo "You do not have enough privileges to use this script"
exit 1
@unnikked
unnikked / CPU.java
Created June 26, 2014 23:11
Tiny RISC Virtual Machine - Read README first!
import java.util.HashMap;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CPU {
public String[] ram;
private HashMap<String, Instruction> rom;
private double accumulator;
private int instructionPointer;
@unnikked
unnikked / Brainfuck.java
Last active September 7, 2022 00:20
Tiny Brainfuck Interpreter Written in Java
import java.util.*;
public class Brainfuck {
private Scanner sc = new Scanner(System.in);
private final int LENGTH = 65535;
private byte[] mem = new byte[LENGTH];
private int dataPointer;
public void interpret(String code) {
int l = 0;
for(int i = 0; i < code.length(); i++) {
@unnikked
unnikked / BaseController.php
Created December 21, 2014 20:21
BaseController class that I use in my FatFreeFramework projects. Based on https://github.com/interagent/http-api-design
<?php
namespace controller\api;
/**
* Base Controller class, it provides some helper methods
* to his child classes.
*
* You can make api calls by setting X-Auth-Token header
* value. All parameters all passed in x-www-urlencoded
@unnikked
unnikked / Event.php
Created March 17, 2015 22:30
PHP Closure Event Dispatcher
<?php
class Event {
private $events = [];
public function on($event, $callback, $priority = 0) {
// check if an event is not already created
if (!isset($this->events[$event])) $this->events[$event] = new \SplPriorityQueue();
// make $this available in closures
if (is_object($callback) && $callback instanceof \Closure) {
@unnikked
unnikked / RPN.java
Created March 25, 2015 18:00
Stack Based Virtual Machine. It uses RPN syntax.
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;
/**
@unnikked
unnikked / real_ip.php
Created March 31, 2015 15:57
Get Real IP Address of Client. This function will fetch the real IP address of the user even if he is behind a proxy server.
<?php
function getRealIpAddr()
{
if (!emptyempty($_SERVER['HTTP_CLIENT_IP']))
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!emptyempty($_SERVER['HTTP_X_FORWARDED_FOR']))
//to check ip is pass from proxy
@unnikked
unnikked / tag_cloud.php
Created March 31, 2015 15:58
Tag Cloud Generator
<?php
function getCloud( $data = array(), $minFontSize = 12, $maxFontSize = 30 )
{
$minimumCount = min($data);
$maximumCount = max($data);
$spread = $maximumCount - $minimumCount;
$cloudHTML = '';
$cloudTags = array();
@unnikked
unnikked / gravatar_show.php
Created March 31, 2015 16:00
Show gravatar from user email
<?php
/******************
*@email - Email address to show gravatar for
*@size - size of gravatar
*@default - URL of default gravatar to use
*@rating - rating of Gravatar(G, PG, R, X)
*/
function show_gravatar($email, $size, $default, $rating)
{