Skip to content

Instantly share code, notes, and snippets.

View isu3ru's full-sized avatar

Isuru Ranawaka isu3ru

  • Sri Lanka
  • 04:43 (UTC +05:30)
View GitHub Profile
@isu3ru
isu3ru / hexAlphaCalculator.java
Created October 20, 2017 04:12
Java code to get each hexadecimal value from 100% to 0% alpha
for (double i = 1; i >= 0; i -= 0.01) {
i = Math.round(i * 100) / 100.0d;
int alpha = (int) Math.round(i * 255);
String hex = Integer.toHexString(alpha).toUpperCase();
if (hex.length() == 1)
hex = "0" + hex;
int percent = (int) (i * 100);
System.out.println(String.format("%d%% — %s", percent, hex));
}
@isu3ru
isu3ru / laravel-blade-cheetsheet.txt
Last active June 10, 2024 04:21
Commands for Laravel Blade template engine
{{ $var }} - Echo content
{{ $var or 'default' }} - Echo content with a default value
{{{ $var }}} - Echo escaped content
{{-- Comment --}} - A Blade comment
@extends('layout') - Extends a template with a layout
@if(condition) - Starts an if block
@else - Starts an else block
<script type="text/javascript">
/* First CSS File */
var giftofspeed = document.createElement('link');
giftofspeed.rel = 'stylesheet';
giftofspeed.href = '../css/yourcssfile.css';
giftofspeed.type = 'text/css';
var godefer = document.getElementsByTagName('link')[0];
godefer.parentNode.insertBefore(giftofspeed, godefer);
/* Second CSS File */
.presentation-title {
font-size: 8em;
font-weight: 700;
margin: 0;
color: #FFFFFF;
background: #fbf8ec;
background: -moz-linear-gradient(top, #FFFFFF 35%, #4e6773 100%);
background: -webkit-linear-gradient(top, #FFFFFF 35%, #4e6773 100%);
background: linear-gradient(to bottom, #FFFFFF 35%, #4e6773 100%);
background-clip: border-box;
@isu3ru
isu3ru / HtaccessSnippets.txt
Last active October 3, 2017 05:11
htaccess snippets
# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
Setting a rewrite rule in .htaccess: use cases
----------------------------------------------
NOTE: The directives specified below work under their own syntax. Changing any symbol or character can lead to improper function or failure of the rewrite rule. To keep things clear, we have highlighted those parts, which can be modified, with red color (mostly where a certain domain name should be placed).
Let’s take an overview of the most common situations in which a redirection from HTTP to HTTPS can be configured.
@isu3ru
isu3ru / rotating_animation.css
Created September 28, 2017 21:03
Rotating ring
.gps_ring {
border: 3px solid #999;
-webkit-border-radius: 30px;
height: 32px;
width: 32px;
display: inline-block;
-webkit-animation: pulsate 1s ease-out;
-webkit-animation-iteration-count: infinite;
opacity: 0.0
}
<?php
function setFlashDataItem($key, $value)
{
if (!array_key_exists('flashdata', $_SESSION)) {
$_SESSION["flashdata"] = array();
}
$_SESSION["flashdata"][$key] = $value;
}
@isu3ru
isu3ru / reloadUrlWithParams.php
Created September 24, 2017 12:59
Reload current url with some parameters
<?php
function reloadUrlWithParams($anchor = false, $params = false)
{
$temparr = array();
if ($params && is_array($params)) {
foreach ($params as $k => $v) {
$temparr[] = urlencode($k) . "=" . urlencode($v);
}
}
<?php
function p($key, $num = FALSE)
{
$var = filter_input(INPUT_POST, $key);
if ($var) {
if (is_array($var)) {
return $var;
}
if (!is_numeric($var) && $num && empty($var)) {
return intval(0);
<?php
function base_url() {
$isSecure = false;
if (isset($_SERVER['HTTPS'])) {
$isSecure = $_SERVER['HTTPS'] == 'on';
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
$isSecure = true;
}
$REQUEST_PROTOCOL = $isSecure ? 'https' : 'http';