Skip to content

Instantly share code, notes, and snippets.

View xtrasmal's full-sized avatar
🟢
--- 200 OK

Xander xtrasmal

🟢
--- 200 OK
  • Cyberspace
View GitHub Profile
@xtrasmal
xtrasmal / loop-post_tags.php
Created May 21, 2013 20:28
WordPress Loop posts per post tag
<?php
$terms = get_terms("post_tag");
$count = count($terms);
if ( $count > 0 ){
foreach ( $terms as $term ) {
echo '<h2>' . $term->name . '</h2>';
echo '<ul>';
$loop = new WP_Query( array(
'post_type' => 'product',
'post_per_page' => 100,
@xtrasmal
xtrasmal / backstretch-random.js
Created May 24, 2013 13:48
Random Backstretch.js background images from array
var images = [
"http://www.netcarshow.org/uploads/42/20081215163952524.jpg",
"http://www.netcarshow.org/uploads/11/20081213162058711.jpg",
"http://www.netcarshow.org/uploads/40/20081223052831150.jpg"
];
// The index variable will keep track of which image is currently showing
var index = 0,oldIndex;
$(document).ready(function() {
<!doctype html>
<head>
<meta charset="utf-8">
<title>Grid test</title>
<link rel="stylesheet" href="css/example.css">
</head>
<body>
<div id="wrapper">
@xtrasmal
xtrasmal / relational-division.sql
Created May 26, 2013 20:16
MySQL Relational division
SELECT Products.*
FROM Products
JOIN ProductTags ON Products.id = ProductTags.product_id
WHERE ProductTags.tag_id IN (1,2,3)
GROUP BY Products.id
HAVING COUNT(DISTINCT ProductTags.tag_id) = 3
/*
Assuming that there is a unique
constraint on product_id,tag_id you
@xtrasmal
xtrasmal / getTweets.php
Created June 6, 2013 18:03
Function to get latest tweets for hash tag
function getTweets($hash_tag) {
$url = 'http://search.twitter.com/search.atom?q='.urlencode($hash_tag) ;
echo "<p>Connecting to <strong>$url</strong> ...</p>";
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
$xml = curl_exec ($ch);
curl_close ($ch);
//If you want to see the response from Twitter, uncomment this next part out:
@xtrasmal
xtrasmal / php
Created June 6, 2013 18:04
Applying Even/Odd Classes
<div class="example-class<?php echo ($xyz++%2); ?>">
@xtrasmal
xtrasmal / gist:5723587
Created June 6, 2013 18:05
Email error logs to yourself
<?php
// Our custom error handler
function nettuts_error_handler($number, $message, $file, $line, $vars){
$email = "
<p>An error ($number) occurred on line
<strong>$line</strong> and in the <strong>file: $file.</strong>
<p> $message </p>";
$email .= "<pre>" . print_r($vars, 1) . "</pre>";
@xtrasmal
xtrasmal / gist:5723598
Created June 6, 2013 18:06
Detect browser language
function get_client_language($availableLanguages, $default='en'){
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$langs=explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($langs as $value){
$choice=substr($value,0,2);
if(in_array($choice, $availableLanguages)){
return $choice;
}
}
@xtrasmal
xtrasmal / main.scss
Created June 20, 2013 14:30
SCSS named mediaquery
@import "mediaquery"
.fart {
width: 25%;
@include breakpoint(tablet-size) {
width: 100%;
}
}
@xtrasmal
xtrasmal / directive.js
Created June 22, 2013 09:55
angular directive
var myModule = angular.module(...);
myModule.directive('directiveName', function (injectables) {
return {
restrict: 'A',
template: '<div></div>',
templateUrl: 'directive.html',
replace: false,
priority: 0,
transclude: false,
scope: false,