Skip to content

Instantly share code, notes, and snippets.

@coto
coto / benchmark-javascript.html
Last active January 5, 2016 21:43
JavaScript Benchmark - Closure vs Prototype
<html>
<head>
<title>Becnhmark - Javascript prototype versus closure execution speed</title>
<script type="text/javascript">
/*
* Author: Coto Augosto
* Twitter: http://twitter.com/coto
* URL: http://beecoss.com
* Created: Nov 30, 2010
*/
@insin
insin / index.html
Last active February 8, 2024 15:14
Export a <table> to Excel - http://bl.ocks.org/insin/1031969
<!DOCTYPE html>
<html>
<head>
<title>tableToExcel Demo</title>
<script src="tableToExcel.js"></script>
</head>
<body>
<h1>tableToExcel Demo</h1>
<p>Exporting the W3C Example Table</p>
@jeremyfelt
jeremyfelt / google-dfp-acm-config.php
Created August 23, 2012 21:23
Google DFP JS Explanation
<?php
/**
* Basic configuration for multiple DFP JS ad tags in Ad Code Manager
*
* Our ad units are named 'test_ad_300x250' and 'test_ad_728x90'
* Our DFP ID is 12345678
* Our ad slot IDs will be automatically created
*
*/
@lost-theory
lost-theory / gist:3925738
Created October 21, 2012 04:29
different delimiters in jinja2 + flask
from flask import Flask, render_template_string, request
class CustomFlask(Flask):
jinja_options = Flask.jinja_options.copy()
jinja_options.update(dict(
block_start_string='<%',
block_end_string='%>',
variable_start_string='%%',
variable_end_string='%%',
comment_start_string='<#',
@cobyism
cobyism / gh-pages-deploy.md
Last active July 2, 2024 13:11
Deploy to `gh-pages` from a `dist` folder on the master branch. Useful for use with [yeoman](http://yeoman.io).

Deploying a subfolder to GitHub Pages

Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. This is useful for things like sites developed with Yeoman, or if you have a Jekyll site contained in the master branch alongside the rest of your code.

For the sake of this example, let’s pretend the subfolder containing your site is named dist.

Step 1

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).

@bytehead
bytehead / last_child.js
Last active December 18, 2015 07:48
last-child selector in ie8
// there is a solution for jQuery < 1.9.0, where you can use `$.browser`:
// https://gist.github.com/nathansmith/950767
// but jQuery removed `$.browser` in version 1.9.0, so you have to get another way:
function last_child() {
if (/msie [1-8]{1}[^0-9]/.test(navigator.userAgent.toLowerCase())) {
$('*:last-child').addClass('last-child');
}
}

HTML5 paste image to page

Using a simpel javascript code found on gist.github.com I have made simpel demo showing how you can paste images on the computer clipboard into HTML elements and save their info as dataURL

A Pen by Sten Hougaard on CodePen.

License.

@hissy
hissy / gist:7352933
Created November 7, 2013 11:07
[WordPress] Add file to media library programmatically
<?php
$file = '/path/to/file.png';
$filename = basename($file);
$upload_file = wp_upload_bits($filename, null, file_get_contents($file));
if (!$upload_file['error']) {
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_parent' => $parent_post_id,
@ThomasBurleson
ThomasBurleson / makeTryCatch.js
Last active December 28, 2015 14:29
Using Promises and AngularJS $log, I demonstrate how to guard targeted function invocations using a `super` version of try-catch. And the guard will report exceptions (with stack traces) via the logger function. If the target function returns a promise, then a rejection handler is attached; which will also report rejections and possible stack tr…
/**
* Implement a tryCatch() method that logs exceptions for method invocations AND
* promise rejection activity.
*
* @param notifyFn Function callback with logging/exception information (typically $log.error )
* @param scope Object Receiver for the notifyFn invocation ( optional )
*
* @return Function used to guard and invoke the targeted actionFn
*/
function makeTryCatch( notifyFn, scope )
@davidpaulsson
davidpaulsson / wp-get_id_by_slug
Created February 26, 2014 06:20
WordPress: Get page ID from slug
// Usage:
// get_id_by_slug('any-page-slug');
function get_id_by_slug($page_slug) {
$page = get_page_by_path($page_slug);
if ($page) {
return $page->ID;
} else {
return null;
}