Skip to content

Instantly share code, notes, and snippets.

View georgioupanayiotis's full-sized avatar
🛰️

Panayiotis Georgiou georgioupanayiotis

🛰️
View GitHub Profile
@georgioupanayiotis
georgioupanayiotis / build.gradle
Created February 26, 2015 14:18
Error:compileSdkVersion android-21 requires compiling with JDK 7
android {
compileSdkVersion 21
buildToolsVersion "21.0.0"
defaultConfig {
minSdkVersion 21
targetSdkVersion 21
}
compileOptions {
@georgioupanayiotis
georgioupanayiotis / MainActivity.java
Last active August 29, 2015 14:16
Load resources from XML in Android
package com.panayiotisgeorgiou.androidxmlresources
import android.support.v7.app.ActionBarActivity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.content.res.TypedArray;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
@georgioupanayiotis
georgioupanayiotis / index.html
Last active August 29, 2015 14:16
Automatically Convert String to Upper Case with Javascript
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function changeEach(el){
var text = document.getElementById(el).value;
var capital = text.toUpperCase();
document.getElementById(el).value = capital;
}
@georgioupanayiotis
georgioupanayiotis / $_SERVER.php
Last active August 13, 2018 07:04
Get visitor IP address in PHP
function get_visitor_ip() {
$ip = '';
if ($_SERVER['HTTP_CLIENT_IP'])
$ip = $_SERVER['HTTP_CLIENT_IP'];
else if($_SERVER['HTTP_X_FORWARDED_FOR'])
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if($_SERVER['HTTP_X_FORWARDED'])
$ip = $_SERVER['HTTP_X_FORWARDED'];
else if($_SERVER['HTTP_FORWARDED_FOR'])
$ip = $_SERVER['HTTP_FORWARDED_FOR'];
@georgioupanayiotis
georgioupanayiotis / single.php
Created February 14, 2015 20:00
Display related posts in WordPress
// related posts
$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 6, 'post__not_in' => array($post->ID) ) );
if( $related ){ ?>
<div class="related_posts">
<h2>Related Tutorials</h2>
<ul>
<?php foreach( $related as $post ) {
setup_postdata($post); ?>
<li>
@georgioupanayiotis
georgioupanayiotis / functions.php
Created February 12, 2015 16:36
CHANGE POST EXCERPT LENGTH IN WORDPRESS
function your_excerpt_length( $length ) {
return 70;
}
add_filter( 'excerpt_length', 'your_excerpt_length' );
@georgioupanayiotis
georgioupanayiotis / gist:4a74b9692fc3194fd993
Created February 3, 2015 15:39
Import data to websites is an important functionality, So in this tutorial will show you how to import CSV data to table with PHP.
// Database configs
$host="localhost";
$dbuser="";
$dbpass="";
$dbname = "";
$link = mysqli_connect($host, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno())
echo mysqli_connect_error();
@georgioupanayiotis
georgioupanayiotis / function.php
Last active August 29, 2015 14:14
Convert an email into link from text in PHP
$string = 'please contact me on email@emaildomain.com';
ereg_replace("[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[A-Za-z]{2,3})", "<a href=\"mailto:\\0\">\\0</a>", $string);
ereg_replace is deprecated therefore we can use:
function convertEmailToLinks($string) {
return preg_replace("/[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[A-Za-z]{2,3})/", "<a href=\"mailto:\\0\">\\0</a>", $string);
}
To check if your device support Bluetooth Low Energy programmically, check (getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)).
Android 4.3 (API Level 18) introduces built-in platform support for Bluetooth Low Energy in the central role and provides APIs that apps can use to discover devices, query for services, and read/write characteristics.
@georgioupanayiotis
georgioupanayiotis / List running service of Android device
Last active November 7, 2022 03:54
List running service of Android device
List running service of Android device