Skip to content

Instantly share code, notes, and snippets.

View pfieffer's full-sized avatar
🦉
Working :/

Ravi Garbuja Pun pfieffer

🦉
Working :/
View GitHub Profile
<?php
//For connecting the database
$link = mysqli_connect("localhost","root","", "practise");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/bootstap-theme.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css">
</head>
<body>
<?php
//For connecting the database-->
$link = mysqli_connect("localhost","root","", "practise");
if (!$link) {
die("Connection failed: " . mysql_error());
}else{
mysqli_select_db ($link, 'practise') or die ("Could not select database.");
}
@pfieffer
pfieffer / DateTypeConverter.java
Last active November 1, 2019 06:55
Date object to Long (TImestamps) and vice versa on Android.
/**
* A utility class to convert date type from java.util.Date to Long and vice versa. This needs to be
* done to store/read the date into/from SQLite database.
*/
public class DateTypeConverter {
public static Date toDate(Long timestamp) {
return timestamp == null ? null : new Date(timestamp);
}
public static Long toTimestamp(Date date) {
<?php
//For connecting the database-->
$link = mysqli_connect("localhost","root","", "practise");
if (!$link) {
die("Connection failed: " . mysql_error());
}else{
mysqli_select_db ($link, 'practise') or die ("Could not select database.");
}
//Start session
@pfieffer
pfieffer / Hex values according to percentage.txt
Last active October 20, 2022 05:19
ARGB where A = Alpha. Opacity levels according to percentage
E.g. for 50% white you'd use #80FFFFFF
100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
@pfieffer
pfieffer / NetworkHelper.java
Last active November 1, 2019 06:54
To find if the Android Device is connected to the internet or not
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
public class NetworkHelper {
public static final boolean hasNetworkAccess(Context context){
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
try {
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
return networkInfo != null && networkInfo.isConnectedOrConnecting();
@pfieffer
pfieffer / FriendlyTimeExtension.kt
Created October 3, 2019 09:46
Get time in user friendly format. Extension function on top of Long class.
fun Long.getFriendlyTime(): String {
val dateTime = Date(this * 1000)
val sb = StringBuffer()
val current = Calendar.getInstance().time
var diffInSeconds = ((current.time - dateTime.time) / 1000).toInt()
val sec = if (diffInSeconds >= 60) (diffInSeconds % 60) else diffInSeconds
diffInSeconds /= 60
val min = if (diffInSeconds >= 60) (diffInSeconds % 60) else diffInSeconds
diffInSeconds /= 60
@pfieffer
pfieffer / change_owner_and_permissions.sh
Last active November 1, 2019 06:52
Change the owner and permsissions to troubleshoot issues with localhost on Linux
$ ls -dl ~/files
drwx------ 9 root root 4096 2009-04-06 15:56 files
$ sudo chown grunt547:grunt547 ~/files
[sudo] password for grunt547:
$ chmod 755 ~/files
$ ls -dl ~/files
drwxr-xr-x 9 grunt547 grunt547 4096 2009-04-06 15:56 files
@pfieffer
pfieffer / BuilderDemo.java
Last active March 5, 2020 10:56
Builder Pattern Demo
// Java code to demonstrate Builder Pattern
// Server Side Code
final class Student {
// final instance fields
private final int id;
private final String name;
private final String address;