Skip to content

Instantly share code, notes, and snippets.

View flangofas's full-sized avatar
🎯
Focusing

Antonis Flangofas flangofas

🎯
Focusing
View GitHub Profile
@flangofas
flangofas / gist:dcbb0cdc3bc4d795c1c1
Last active August 29, 2015 14:02
Find replace bash executable PHP script
#!/usr/bin/php
<?php
/**
* Find replace tool
* Place it in the executable folder "/usr/local/sbin/"
* Also, add an alias in the ~/.bashrc
* Option should be -e for execute
* Otherwise view the files only that contain the search term
* Author: Antonis Flangofas
* Date: 01/06/2014
@flangofas
flangofas / ConvertMS.js
Last active February 29, 2024 17:22
JS: Convert Milliseconds to days? minutes? seconds? or all!
function convertMiliseconds(miliseconds, format) {
var days, hours, minutes, seconds, total_hours, total_minutes, total_seconds;
total_seconds = parseInt(Math.floor(miliseconds / 1000));
total_minutes = parseInt(Math.floor(total_seconds / 60));
total_hours = parseInt(Math.floor(total_minutes / 60));
days = parseInt(Math.floor(total_hours / 24));
seconds = parseInt(total_seconds % 60);
minutes = parseInt(total_minutes % 60);
@flangofas
flangofas / Fibonacci
Created August 3, 2014 20:21
Fibonacci sequence
<?php
echo fibonacciCode($argv[1]) . PHP_EOL;
/**
* This function returns the fibonacci sequence
*
* @param mixed sequence
* @return int total
*/
@flangofas
flangofas / .vimrc
Created August 10, 2014 18:39
My .vimrc
syntax on
set number
set wrap
set laststatus=2 " Always show the statusline
set title " Set the title of the window in the terminal to the file
set history=500 " History
set backup
"Followin cmd must be configure with X11
set clipboard+=unnamed " Yank to system clipboard
set showcmd " Display an incomplete command in the lower right corner of the Vim window
@flangofas
flangofas / FileFinder.php
Last active October 24, 2023 19:56
Search for specific type files under specific directories using RecursiveFilterIterator
<?php
$obj = new FileFinder($argv[1]);
$obj->setFileType(array_slice($argv, 2));
$obj->setExcludingDirectories(array('test1'));
$pages = $obj->find();
print_r($pages);
class FileFinder
@flangofas
flangofas / FindReplace.php
Last active August 29, 2015 14:05
Find and Replace using CSV
<?php
class FindReplace{
const TOKEN = '&&';
const HYPHEN = '-';
const TARGETDIR = 'modified';
const TEMPLATESDIR = 'templates';
public $data = array();
public $filename;
@flangofas
flangofas / wordcounter.php
Created August 17, 2014 23:39
Count words from text file
<?php
/*
* Count number of words from the given txt file
* @author Antonis Flangofas
* @date 18/08/2014
*/
class WordCounter
{
const ASC = 2;
const DESC = 4;
@flangofas
flangofas / observers.php
Last active August 29, 2015 14:12 — forked from mt3o/observers.php
<?php
class MyObserver implements SplObserver {
public function update(SplSubject $subject) {
echo __CLASS__ . ' - ' . $subject->getName();
}
}
class MySubject implements SplSubject {
private $_observers;
@flangofas
flangofas / articlelist_api.php
Last active August 26, 2016 21:39
CakePHP 2 API ArticleList using bitwise operators
<?php
App::uses('ArticleListsAppModel', 'ArticleLists.Model');
/**
* ArticleList Model
*
* @property ArticleListPost $ArticleListPost
*/
class ArticleList extends ArticleListsAppModel {
const MASK_ID = 1;
@flangofas
flangofas / last_segment
Created January 29, 2015 14:57
Get last segment from URL
/**
* Get last segment from URL
* @note array.filter browser support: IE.9+, Firefox 1.5 +
* @return string URL last segment
*/
function getLastSegmentFromUrl() {
path = window.location.pathname;
segments = path.split('/');
//remove empty spaces
segments = segments.filter(function(item) {