Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Remigijus Jarmalavičius ReekenX

🏠
Working from home
Block or report user

Report or block ReekenX

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ReekenX
ReekenX / prestashop_fix_for_apache
Created May 9, 2014
Prestashop 1.6 fix for Apache 2.4 (only for dev mode!)
View prestashop_fix_for_apache
find -iname '.htaccess' -exec sed 's/Deny from all//' -i {} \;
View pomodoro.bash
#!/bin/bash
# Public domain license
# Not original author: Remigijus Jarmalavičius
#
# Usage:
# pomodoro "title for work"
filename="/home/remigijus/Kodas/smelio-deze/`date '+%Y-%m-%d'`.log"
@ReekenX
ReekenX / mysql_grant_access.sql
Created Mar 20, 2012
Mysql: Grant access to single database
View mysql_grant_access.sql
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, LOCK TABLES, INDEX ON db_name.* TO db_username@localhost IDENTIFIED BY 'super duper secret password';
View force_file_downloading.php
<?php
function downloadFile($file){
$file_name = $file;
$mime = 'application/force-download';
header('Pragma: public'); // required
header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header('Content-Type: '.$mime);
@ReekenX
ReekenX / get_real_ip.php
Created Mar 19, 2014
GET real IP address (under proxy)
View get_real_ip.php
<?php
function get_real_ip() {
$proxy_headers = array(
'CLIENT_IP',
'FORWARDED',
'FORWARDED_FOR',
'FORWARDED_FOR_IP',
'HTTP_CLIENT_IP',
'HTTP_FORWARDED',
@ReekenX
ReekenX / random_string_generator.php
Created Mar 19, 2014
Random string generator from dataset
View random_string_generator.php
<?php
function genRandomString($length) {
$characters = "0123456789abcdefghipqrstuvwxyz";
$string = "";
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters) - 1)];
}
return $string;
}
@ReekenX
ReekenX / starts_with_ends_with.php
Created Mar 19, 2014
Functions startsWith() and endsWith() like in Python
View starts_with_ends_with.php
<?php
function startsWith($haystack, $needle) {
return !strncmp($haystack, $needle, strlen($needle));
}
function endsWith($haystack, $needle) {
$length = strlen($needle);
if ($length == 0) {
return true;
View thumbnail_from_youtube.php
function video_image($url){
$image_url = parse_url($url);
if($image_url['host'] == 'www.youtube.com' ||
$image_url['host'] == 'youtube.com'){
$array = explode("&", $image_url['query']);
return "http://img.youtube.com/vi/".substr($array[0], 2)."/0.jpg";
}else if($image_url['host'] == 'www.youtu.be' ||
$image_url['host'] == 'youtu.be'){
$array = explode("/", $image_url['path']);
return "http://img.youtube.com/vi/".$array[1]."/0.jpg";
View unzip.php
<?php
$zip = zip_open("compressed.zip");
if ($zip) {
while ($zip_entry = zip_read($zip)) {
$fp = fopen(zip_entry_name($zip_entry), "w");
if (zip_entry_open($zip, $zip_entry, "r")) {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
fwrite($fp,"$buf");
zip_entry_close($zip_entry);
fclose($fp);
View validate_url.php
<?php
$url = "http://example.org/";
if (preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $url)) {
echo "Your url is ok.";
} else {
echo "Wrong url.";
}
You can’t perform that action at this time.