Skip to content

Instantly share code, notes, and snippets.

@i5ar
i5ar / substring.php
Last active August 17, 2017 16:37
Get the first 500 characters
<?php
$string = $post->post_content;
$newString = substr($string, 0, 500);
echo $newString;
?>
@i5ar
i5ar / referer.php
Last active August 17, 2017 16:38
Get last URL visited
<?php
// strrpos(); finds the position of / from the end of the string;
// substr(); extracts a sub string till the position of / found in previous step.
$url = $_SERVER['HTTP_REFERER'];
echo $url . '<br />'; // http://localhost/mydomain/first/second/
$link = substr($url, 0, strrpos($url, "/"));
echo $link; // http://localhost/mydomain/first/second
?>
<?php
@i5ar
i5ar / gist:d016372e5574b71421af
Last active August 29, 2015 14:05
Responsive Circle
/* Responsive Circle */
.circle-text {
width:50%;
margin-left:auto;
margin-right:auto;
}
.circle-text:after {
content: "";
display: block;
width: 100%;
/* Triangle */
.triangle { position: relative; }
.triangle::before {
border-top: 0;
border-right: 175px solid transparent;
border-bottom: 175px solid transparent;
border-left: 175px solid #af2715;
position: absolute;
content: "";
z-index:3;
@i5ar
i5ar / gist:b7f97ed51ba6974a8982
Last active October 30, 2015 18:20
Twitter Indent
<?php
// Assigning Twitter form
$text = 'An awesome tweet'; // The tweet text
$url_page = 'http://localhost/mydomain/page-name'; // The tweet link
$account = 'i5ar'; // The tweet account
// Encoding
$url = urlencode($text);
$url.= "+".rawurlencode($url_page);
$url.= "+via+".urlencode('@').urlencode($account);
@i5ar
i5ar / gist:20596d66988eb40be6cc
Last active August 29, 2015 14:07
Forms with Conditional Logic
jQuery(document).ready(function() {
// Hide the field initially
jQuery(".field_2").hide(); // <div class="field_2">
// Show the text field only when the third option is chosen - this doesn't
jQuery('#field_1').change(function() { // <select id="field_1">
if (jQuery("#field_1").val() == "Nope") { // <option value="Nope">
jQuery(".field_2").show();
} else {
jQuery(".field_2").hide();
}
@i5ar
i5ar / gist:cf09395ac8de27a4c9e2
Last active August 29, 2015 14:09
Get BuddyPress User's Group
$group_ids = groups_get_user_groups( bp_loggedin_user_id() );
var_dump( $group_ids["groups"] );
foreach( $group_ids["groups"] as $id ) {
$group = groups_get_group( array( 'group_id' => $id ) );
echo '<pre>';
var_dump( $group );
echo '</pre>';
}
// Print group name
$group_name = $group->name;
@i5ar
i5ar / gist:d00be523d57c19506a99
Last active August 29, 2015 14:10
Organization
# Add file extension
import os
import glob
os.chdir("C:/Users/myFolder")
aList = []
for file in glob.glob("*"):
print(file)
# Add extension if does not exist
if '.' not in file:
@i5ar
i5ar / gist:bccf36e165a0747028a4
Last active August 29, 2015 14:10
Sphinx Hack
d = vars(opts)
- for k, v in d.items():
+ for k, v in list(d.items()):
# delete None or False value
if v is None or v is False:
del d[k]
@i5ar
i5ar / gist:dae5ef2105f21c032c00
Last active August 29, 2015 14:10
Sverchok Simple Cross Section
{
"export_version": "0.054",
"framed_nodes": {},
"groups": {},
"nodes": {
"Axis Input": {
"bl_idname": "svAxisInputNode",
"color": [
0.6079999804496765,
0.6079999804496765,