Skip to content

Instantly share code, notes, and snippets.

View apphp's full-sized avatar

Samuel Akopyan apphp

View GitHub Profile
@apphp
apphp / gist:68786f4c743f7ee562e5a95072199674
Created December 18, 2020 10:03
Creating Collapse Sliding Side Panel in CSS
<style type="text/css">
// source: https://www.apphp.com/index.php?snippet=css-collapsible-sliding-side-panel
// You may define side panel, that will slide whether on button click on on window size changing.
#sidepane{
display: block;
position: absolute;
transform: translateX(-100%);
transition: transform ease-out 0.2s;
}
#sidepane.fadeIn{
@apphp
apphp / htaccess-prevent-access-to-single-file-or-multiple-files
Created September 21, 2017 15:58
Prevent Access to a Specific File/s in .htaccess
# source: http://www.apphp.com/index.php?snippet=htaccess-prevent-access-to-single-file-or-multiple-files
# Prevent viewing of a specific file
<files file.jpg>
Order allow,deny
Deny from all
</files>
# Prevent access to multiple file types
<FilesMatch "\.(htaccess|htpasswd|ini|phps|fla|psd)$">
# source: http://apphp.com/index.php?snippet=htaccess-www-or-no-www
# Force the www.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^your-site.com [NC]
RewriteRule ^(.*)$ http://www.your-site.com/$1 [L,R=301]
# Remove the www.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^your-site.com$ [NC]
@apphp
apphp / mysql-get-random-record-based-on-weight
Created June 11, 2017 19:09
Get Random Record Based on Weight
-- http://www.apphp.com/index.php?snippet=mysql-get-random-record-based-on-weight
-- Must have as field named 'weight'
SELECT * FROM `table` ORDER BY RAND() * (1 / `weight`)
@apphp
apphp / mysql-insert-or-update-if-unique-key-already-exists
Created June 11, 2017 19:08
Insert or Update Record if Unique Key Already Exists
-- source: http://www.apphp.com/index.php?snippet=mysql-insert-or-update-if-unique-key-already-exists
-- Unique key for table must be pre-defined
INSERT INTO `tableName`
VALUES (field1,field2,field3,'-1',...,fieldN,'0')
ON DUPLICATE KEY
UPDATE `field1` = 'abc', `field2` = '123'
@apphp
apphp / html-5-article-structure
Created June 4, 2017 18:59
HTML5 Article Structure with News
// source: http://www.apphp.com/index.php?snippet=html-5-article-structure
<article class="entry">
<header>
<h1 class="entry-title">What you think about all this?</h1>
<time class="updated" datetime="2013-12-01 01:12:02-0300" pubdate>01-12-2013</time>
<p class="byline author vcard">
By <span class="fn">John Smith</span>
</p>
</header>
@apphp
apphp / html-post-data-into-iframe
Created June 4, 2017 18:57
Post Data to iFrame with HTML Only
// source: www.apphp.com/index.php?snippet=html-post-data-into-iframe
<form action="iframe.php" target="my_iframe" method="post">
<label for="text">Name:</label>
<input type="text" name="full_name">
<label for="text">Email:</label>
<input type="text" name="email">
<input type="submit" value="post">
</form>
<iframe name="my_iframe" src="iframe.php"></iframe>
@apphp
apphp / Non-Transparent Inside Transparent Elements
Created May 29, 2017 20:14
Non-Transparent Inside Transparent Elements
<style type="text/css">
/* source: http://www.apphp.com/index.php?snippet=css-non-transparent-inside-transparent-elements */
.bar {
height: 4em;
padding-top: 2em;
opacity: 0.5;
background: black;
border-top: 3px solid #ccc;
border-bottom: 3px solid #ccc;
margin-top: 5.0em;
@apphp
apphp / align-background-in-css
Created May 29, 2017 20:13
Align Backgroud Image with Offset in CSS
<style type="text/css">
/* source:apphp.com/index.php?snippet=css-align-backgroud-image-with-offset */
#sidebar ul li li a {
background-image:url(../images/side-li-rtl.png); background-position:right 15px top 9px;
}
</style>
@apphp
apphp / Display Random Quotes with JavaScript
Created May 24, 2017 18:40
This snippet code allows you to prevent the viewer from being able to right-click on your page. This can discourage the average user from borrow images or code from your site.
<script type="text/javascript">
// source: www.apphp.com/index.php?snippet=javascript-display-random-quotes
writeRandomQuote = function () {
var quotes = new Array();
quotes[0] = "Action is the real measure of your intelligence.";
quotes[1] = "The baseball has a great advantage over cricket of being sooner ended.";
quotes[2] = "Every goal, every action, every thought, every feeling one experiences, whether it be consciously or unconsciously known, is an attempt to increase one’s level of peace of mind.";
quotes[3] = "A good head and a good heart are always a formidable combination.";
var rand = Math.floor(Math.random()*quotes.length);
document.write(quotes[rand]);