Skip to content

Instantly share code, notes, and snippets.

@begedin
begedin / paging-code.js
Last active August 29, 2015 14:01
Simple implementation of paging on a collection in knockout.
function Paging(itemSet) {
/// <summary>Component used to apply paging on a provided collection. Requires knockout.</summary>
/// <param name="itemSet" type="ko.observableArray or Array">Collection to apply the paging on.</param>
var self = this;
self.page = ko.observable(1); // currently active page, starts from 1 for increased "user friendliness"
self.itemsPerPage = ko.observable(20); // currently selected number of items per page
self.itemsPerPageOptions = [10, 20, 50, 100]; // available options for number of items per page
/// <summary>
/// A knockout computed observable that supports async data.
/// To use it, set a function that returns a deferred object, for instance, an AJAX call as the parameter.
/// While using AJAX, if server data isn't in proper format, you can use $.ajax().pipe() to map it correctly.
/// http://api.jquery.com/deferred.pipe/
///
/// There are two helper observables added to the asyncComputed
/// .inProgress returns true if data is not yet loaded (is currently being loaded)
/// .loaded is the opposite and returns true if data has been loaded
/// </summary>
@begedin
begedin / ember-micro-addon-implementation.md
Last active August 29, 2015 14:23
Implementation techniques used in ember-micro-addon

How is the flat file structure working within an ember-app?

The addon's entry point, index.js is key here.

The addon exposes several hooks during addon/app build-time, several of which are treeForX where X is some part of the app/addon. In our case, depending on the addon type, we hook into one or more of theese hooks, at which point, we restructure and rename the files on the fly, so they're conventionally placed and named by the time the parent app tries to load them.

For components

  • treeForApp moves component.js to app/components/addonName.js
  • treeForTemplate moves template.hbs to app/templates/components/addonName.hbs
@begedin
begedin / testing-micro-addons.md
Created July 6, 2015 10:22
Testing micro-addons

What we have right now

We have a simple, flat file structure with the scripts that need testing named component.js, library.js and helper.js depending on the type of micro-addon. A micro-component additionally has a style.css and a template.hbs, but those are not really tested directly, and would only be tested indirectly, via component.js.

What happens with those files right now is that, when the addon is being consumed in a parent app, there are hooks in the addon's index.js script which cause the files during build time, to get renamed and copied to their proper, ember addon defined locations within the app\ folder of the parent app.

What we would want

I think ideally, we would want a tests.js file within the existing flat file structure. Depending on the type of micro-addon, this file would contain a unit test module either for a component, or a general unit test in case of a library and/or helper.

@begedin
begedin / gist:5200602
Created March 19, 2013 22:10
HTML structure for basic full screen layout
<body>
<header></header>
<section>
<div class="column-left"></div>
<div></div>
<div class="column-right"></div>
</section>
<footer></footer>
</body>
@begedin
begedin / ProgrammingHowTo Full Screen Layout.css
Created March 19, 2013 22:21
Full screen layout in CSS, fixed header and footer
header, footer {
position: fixed;
width: 100%;
background-color: black;
}
header {
top: 0;
height: 50px;
}
@begedin
begedin / ProgrammingHowTo Full Screen Section.css
Created March 19, 2013 22:23
full screen layout in CSS, fixed middle section
section {
position: fixed;
width: 100%;
top: 50px;
bottom: 100px;
}
@begedin
begedin / ProgrammingHowTo - HTML Full Screen Section.html
Last active December 15, 2015 04:19
Full screen HTML layout in CSS, section with columns
<section>
<div class="column-left"></div>
<div></div>
<div class="column-right"></div>
</section>
@begedin
begedin / ProgrammingHowTo - CSS Full Screen Sidebars.css
Created March 19, 2013 22:25
full screen HTML layout in CSS, the final CSS for columns
.column-left, .column-right {
position: absolute;
height: 100%;
background-color: bisque;
width: 200px;
}
.column-left {
left: 0px;
}
.column-right {
@begedin
begedin / Close All Pings Safely.sql
Created April 21, 2013 17:27
How to disable Pingback and Trackback Spam on Wordpress - SAFER METHOD
UPDATE wp_posts SET ping_status='closed'
WHERE post_status = 'publish'
AND post_type = 'post';
UPDATE wp_posts SET ping_status='closed'
WHERE post_status = 'publish'
AND post_type = 'page';