Skip to content

Instantly share code, notes, and snippets.

Avatar
🙈
ASCII stupid question, get a stupid ANSI!

Jonas Raneryd kaskajp

🙈
ASCII stupid question, get a stupid ANSI!
View GitHub Profile
@kaskajp
kaskajp / localStorageTest.js
Last active Jan 9, 2016
Test if localStorage is available
View localStorageTest.js
function localStorageTest(){
var test = 'test';
try {
localStorage.setItem(test, test);
localStorage.removeItem(test);
return true;
} catch(e) {
return false;
}
}
View notifications.js
//http://www.w3.org/TR/notifications/
//https://developer.mozilla.org/en-US/docs/Web/API/notification
//Notifier.isSupported
//
//Notifier.permission //"granted", "denied", or "default"
//
//Notifier.requestPermission([callback]) //first argument of callback is the current permission
//
//Notifier.notify(title[, options])
View grid.scss
$gridgutter: 30;
$gridpadding: 30;
$gridsize: 978 + ($gridpadding*2);
$gridcolsize: (($gridsize - ($gridgutter * 11)) / 12);
.grid {
width: 100%;
max-width: $gridsize+px;
margin: 0 auto;
padding-left: $gridpadding+px;
padding-right: $gridpadding+px;
@kaskajp
kaskajp / example.html
Created Mar 17, 2015
Responsive Flexbox Example
View example.html
<div class="container">
<div class="image">
<img src="http://placetokyo.com/100/100" alt="" />
</div>
<div class="name-location">
<div class="name">This be the name</div>
<div class="location">This be the location</div>
</div>
<div class="buttons">
<a href="#">Button</a>
@kaskajp
kaskajp / sequence-addclass.js
Last active Aug 29, 2015
Sequence Add Class
View sequence-addclass.js
var sequenceAddClass = function(els) {
function addClassWithTimeout(i, el) {
var t = setTimeout(function() {
clearTimeout(t);
el.className = el.className + "addsomeclass";
}, i * 200);
}
for (var i = 0; i < els.length; i++) {
addClassWithTimeout(i, els[i]);
}
@kaskajp
kaskajp / animate-pathstring.js
Last active Aug 29, 2015
Animate Path String with RaphaelJS
View animate-pathstring.js
var animatePathString = function(canvas, colorNumber, pathString) {
var line = canvas.path(pathString).attr({
stroke: colorNumber
});
var length = line.getTotalLength();
$('path[fill*="none"]').animate({
'to': 1
}, {
@kaskajp
kaskajp / my-cpt.php
Created Mar 17, 2015
Custom Post Type as Plugin
View my-cpt.php
<?php
/*
Plugin Name: A Custom Post Type
Plugin URI: http://kaska.jp/
Description: A simple barebones custom post type.
Version: 1.0
Author: Jonas Raneryd
Author URI: http://kaska.jp/
License: MIT
*/
@kaskajp
kaskajp / wp-cpt-loop.php
Created Mar 17, 2015
Custom Post Type Loop
View wp-cpt-loop.php
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array(
'post_type' => 'myposttype',
'posts_per_page' => 10,
'paged' => $paged)
);
?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
View woocommerce-optimize-scripts.php
<?php
/**
* Optimize WooCommerce Scripts
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
View file-upload-handler.php
<?php /* This function attaches the image to the post in the database, add it to functions.php */
function insert_attachment($file_handler,$post_id,$setthumb='false') {
// check to make sure its a successful upload
if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');