Tuesday, 10 July 2018
password_verify() returns false for correct password
Wednesday, 30 May 2018
How do I get a YouTube video thumbnail from the YouTube API?
https://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
1.jpg, 2.jpg, 3.jpg) is:https://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/sddefault.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg
i3.ytimg.com works in place of img.youtube.com in the example urls above.Tuesday, 29 May 2018
Python: Validate Phone Numbers
Here is a short example demonstrating the use of phonenumbers package. I am using "None" as the country. Any country can be used such as e.g. "GB", "US"
Remember to
pip install phonenumbers
And
import phonenumbers;
def validate_phone(value): try: parsed_number = phonenumbers.parse(value, None) if not phonenumbers.is_valid_number(parsed_number) or
not phonenumbers.is_possible_number(parsed_number):
print("Please provide a valid phone number e.g +CountryCodeNumber") return False except phonenumbers.phonenumberutil.NumberParseException:
print("Please provide a valid phone number e.g +CountryCodeNumber") return False
return True
Monday, 28 May 2018
Could not open input file: artisan
cd command in terminal for example cd myproject.php artisan serve will run default project.PHP PDO Insert Method
<?php
class Contact
{
private $UploadedFiles = '';
private $DbHost = DB_HOST;
private $DbName = DB_NAME;
private $DbUser = DB_USER;
private $DbPass = DB_PASS;
private $table;
function __construct()
{
$this->table = strtolower(get_class());
}
public function insert($values = array())
{
$dbh = new PDO("mysql:host=$this->DbHost;dbname=$this->DbName", $this->DbUser, $this->DbPass, array(PDO::ATTR_PERSISTENT => true));
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->exec("SET CHARACTER SET utf8");
foreach ($values as $field => $v)
$ins[] = ':' . $field;
$ins = implode(',', $ins);
$fields = implode(',', array_keys($values));
$sql = "INSERT INTO $this->table ($fields) VALUES ($ins)";
$sth = $dbh->prepare($sql);
foreach ($values as $f => $v)
{
$sth->bindValue(':' . $f, $v);
}
$sth->execute();
//return $this->lastId = $dbh->lastInsertId();
}
}
Thursday, 24 May 2018
How to use virtualenv with python3.6 on ubuntu16.04
I encountered this problem while using Ubuntu 16.04. When I created virtual environment it used python2.x which is already there in Ubuntu.
python3 -m venv .
Check if your virtual environment is using latest python 3 by activating virtual environemnt by:
source bin/activate
python -V
Below is the older method of doing the same. Try if the above method is not working:
Here is how to switch to python 3.6
sudo apt-get install python-virtualenv
virtualenv --python=python3.6 venv
venv is the name of virtual environment
if there is an error that python3-env is not located then run
sudo apt install python3.6-venv
-----------------------------------------------------------------------------------------------------------------------
OR
sudo apt install -y python3-venv
python3 -m venv env (env is the name of the python environment)
Finally, activate your virtual environment.
source venv/bin/activate
We can use
which python
To check which python is being used once you have activated your virtual environment.
Wednesday, 23 May 2018
Django: Delete Postgres database in Ubuntu
sudo su postgres
psql
Now the database can be dropped by using the following command:
drop database database_name;
Tuesday, 10 February 2015
Android: TableLayout Round Corners
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#006600" />
<corners android:radius="10dp" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
</shape>
Then use the above (roundtablecorner.xml) file as the background for a TableLayout
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/roundtablecorner">
Choose the background color in the shape in:
<solid android:color="#006600" />