Skip to content

Instantly share code, notes, and snippets.

View ReekenX's full-sized avatar
💻
React, Vue, Rails, Python

Remis Jarmalavicius ReekenX

💻
React, Vue, Rails, Python
View GitHub Profile
@ReekenX
ReekenX / unzip.php
Created March 19, 2014 04:59
Unzip files
<?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);
@ReekenX
ReekenX / thumbnail_from_youtube.php
Created March 19, 2014 04:59
Thumbnail from youtube
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";
@ReekenX
ReekenX / starts_with_ends_with.php
Created March 19, 2014 04:58
Functions startsWith() and endsWith() like in Python
<?php
function startsWith($haystack, $needle) {
return !strncmp($haystack, $needle, strlen($needle));
}
function endsWith($haystack, $needle) {
$length = strlen($needle);
if ($length == 0) {
return true;
@ReekenX
ReekenX / random_string_generator.php
Created March 19, 2014 04:57
Random string generator from dataset
<?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 / get_real_ip.php
Created March 19, 2014 04:57
GET real IP address (under proxy)
<?php
function get_real_ip() {
$proxy_headers = array(
'CLIENT_IP',
'FORWARDED',
'FORWARDED_FOR',
'FORWARDED_FOR_IP',
'HTTP_CLIENT_IP',
'HTTP_FORWARDED',
@ReekenX
ReekenX / force_file_downloading.php
Created March 19, 2014 04:55
Force file downloading
<?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 / min_height.css
Created March 19, 2014 04:36
Min height for all browsers
#div {
min-height: 500px;
height:auto !important;
height: 500px;
}
@ReekenX
ReekenX / media_queries.css
Created March 19, 2014 04:34
CSS media queries
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
@media only screen
and (min-width : 321px) {
@ReekenX
ReekenX / secure_ssh_key_generation.bash
Created March 19, 2014 04:30
Secure SSH key generation
ssh-keygen -b 4048 -t rsa -C "Description for secure key"
@ReekenX
ReekenX / social_sharing_links.txt
Created March 19, 2014 04:29
Social sharing links