Skip to content

Instantly share code, notes, and snippets.

View nikos-glikis's full-sized avatar

Nikos Glikis nikos-glikis

View GitHub Profile
@nikos-glikis
nikos-glikis / runner.java
Last active August 29, 2015 14:16
Convert mysql DateTime to java Calendar
/**
* Converts a mysql DateTime String to java Calendar
* @param dateString
* @return Calendar
*/
public static Calendar mysqlDateTimeToCalendar(String dateString)
{
try
{
//in my case I hade an . in the end of the date String.
@nikos-glikis
nikos-glikis / kill.sh
Created August 8, 2015 08:29
kill all commands that match text (ps aux)
ps aux | grep "text" | awk '{print $2}' | xargs kill
@nikos-glikis
nikos-glikis / 0_reuse_code.js
Last active August 29, 2015 14:27
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@nikos-glikis
nikos-glikis / download_file.py
Last active August 29, 2015 14:27
Download File Python
def download_file(url, local_file):
u = urllib2.urlopen(url)
f = open(local_file , 'wb')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading: %s Bytes: %s" % (local_file , file_size)
file_size_dl = 0
block_sz = 8192
@nikos-glikis
nikos-glikis / delete_directory.py
Created August 9, 2015 13:49
Recursive delete directory contents with python
def delete_directory_contents(folder):
for the_file in os.listdir(folder):
file_path = os.path.join(folder, the_file)
try:
if os.path.isfile(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path): shutil.rmtree(file_path)
except Exception, e:
print e
#include <stdio.h>
#include <stdlib.h>
int main()
{
//Why is this happening ?????????
float x = 0.1;
while (x!=1.1)
{
printf("x = %f\n", x);
#repeat x times
#run 5 ls - runs ls 5 times
function run() {
number=$1
shift
for n in $(seq $number); do
$@
sleep 1
done
}
/**
* Clean database. Truncates all tables except from everything that loads with fixtures.
* Used as a fast clean.
*/
public function cleanDB()
{
$excludeTables = array();
$em = $this->em;
$connection = $em->getConnection();
@nikos-glikis
nikos-glikis / mod_all_domain_dirs.php
Created May 11, 2017 18:17
Directadmin - reset user files and folders permissions + restrict php files.
<?php
//this: https://help.directadmin.com/item.php?id=589
$dirs = scandir('/home/');
shuffle($dirs);
$ignoreDirs = [
'.',
'..',
'tmp',
'ftp',
@nikos-glikis
nikos-glikis / rsync_complete_system.sh
Created May 16, 2017 15:55
rsync a live linux system
#- if use a different port, change the port.
rsync -av -exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found} -z --rsh='ssh -p22' --delete --progress --exclude root@remotehost.com /local/destination