Skip to content

Instantly share code, notes, and snippets.

View gabyfle's full-sized avatar
:octocat:
I like Git, C#, OCaml, Lua and Linux.

Gabriel Santamaria gabyfle

:octocat:
I like Git, C#, OCaml, Lua and Linux.
View GitHub Profile
@gabyfle
gabyfle / split.c
Created October 26, 2018 17:14
Implementation of C split() function
short split(char string[], char * words[])
{
const char separators[] = ",; :";
char * token;
short i = 0;
token = strtok(string, separators);
while (token != NULL)
{
@gabyfle
gabyfle / integerdivision.lua
Created March 12, 2019 18:18
Lua integer division with rest
function integerDivision(dividend, divider)
if divider == 0 then error("Stupid! You can't divide by 0!") end
local rest = dividend
local quotient = 0
while rest >= divider do
dividend = dividend - divider
rest = dividend
@gabyfle
gabyfle / total_hours.php
Created March 23, 2019 12:33
Gets game count and total hours for a specific Steam account.
<?php
/**
* Gets steam stats from Steam's API
* @author Gabriel Santamaria <gaby.santamaria@outlook.fr>
*/
$steam_api = "APIKEYLOL";
$steam_id = "76561198127516196";
$jsonurl = "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=" . $steam_api . "&steamid=" . $steam_id . "&format=json";
$json = file_get_contents($jsonurl);
@gabyfle
gabyfle / languages_stats.php
Last active March 31, 2019 10:38
Gets particular user's languages statistics, based on owned repositeries. Gets owned repositeries number.
<?php
/**
* Gets github stats from Github's API
* @author Gabriel Santamaria <gaby.santamaria@outlook.fr>
*/
$github_user = "Gabyfle";
$github_token = "YOURGITHUBTOKEN";
$get_options = [
@gabyfle
gabyfle / write_ini_file.php
Last active April 3, 2019 19:58
Write and modify a parameter in an ini file.
<?php
/**
* Write a new $value in a $param for an .ini file
*
* @param string $path path of the .ini file
* @param string $param parameter to change
* @param string $value value to put in $param
* @return string
*/
function write_ini_file(string $path, string $param, string $value)
@gabyfle
gabyfle / get_latest_release_name.php
Last active April 19, 2019 18:26
Gets the latest release (includes pre-releases) name (based on Tag names) of a Github-hosted repository
<?php
/**
* Parse the owner's name and the name of the repository (works only with github)
*
* @param string $repo_url the repositery url
* @return array [1] : the owner's name [2] : the repo name
*/
function parse_repo_name(string $repo_url)
{
$pattern = '/^https?:\/\/(?:www.)?github\.com\/(.*)\/(.*)/';
@gabyfle
gabyfle / reboot_prevent.lua
Created April 21, 2019 14:26
Gmod Lua server restart prevent
local config = {
['commandName'] = 'reboot_prevent',
['timer'] = 10,
['iterations'] = 5
}
if SERVER then
local timerIteration = 1
function launchReboot(time)
@gabyfle
gabyfle / isZip.php
Created April 27, 2019 22:21
Checks if an uploaded file is a .zip one.
<?php
function isZip(string $tmp, string $name)
{
$extension = pathinfo($name, PATHINFO_EXTENSION);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$type = finfo_file($finfo, $tmp);
return $type === 'application/zip' && $extension === 'zip';
}
@gabyfle
gabyfle / delete_directory.php
Last active May 2, 2019 18:56
Deletes recursively a directory from the server's disk
<?php
/**
* Delete recursively a directory
* Gist : https://gist.github.com/Gabyfle/d7e74e70da6efbeab1c3b2f9636dc178
*
* @param string $path
*/
function delete_directory(string $path): void
{
$files = new \DirectoryIterator($path);
@gabyfle
gabyfle / dms.lua
Last active May 7, 2019 18:49
Gets number of days, hours, minutes and seconds from an amount of seconds
-- Number of seconds to convert
local seconds = 1850
-- 1 day = 86400 s
-- 1 hour = 3600 s
-- 1 minute = 60 s
local days = math.floor(seconds / 86400)
local hours = math.floor((seconds - days * 86400) / 3600)
local minutes = math.floor((seconds - days * 86400 - hours * 3600) / 60)