Skip to content

Instantly share code, notes, and snippets.

View twokul's full-sized avatar
😎
mischief, mostly.

Alex Navasardyan twokul

😎
mischief, mostly.
View GitHub Profile
@twokul
twokul / set-image-src-attribute.hbs
Created February 9, 2015 02:26
lazy-loading-image-in-ember
<img {{bind-attr src=lazyUrl}} />
@twokul
twokul / set-image-src-attribute.js
Last active August 29, 2015 14:15
lazy-loading-image-in-ember
import { get, set } from 'ember';
import InViewportMixin from '../mixins/in-viewport';
export default Component.extend(InViewportMixin, {
lazyUrl: null,
elementInViewport: observer('enteredViewport', function() {
// assuming the url was passed into the component
set(this, 'lazyUrl', get(this, 'url'));
}).on('didInsertElement')
@twokul
twokul / element-in-viewport.js
Created February 9, 2015 02:21
lazy-loading-image-in-ember
export default Component.extend(InViewportMixin, {
elementInViewport: observer('enteredViewport', function() {
// do crazy things!
}).on('didInsertElement')
});
@twokul
twokul / image-onload.js
Last active August 29, 2015 14:15
lazy-loading-image-in-ember
(function() {
// assuming the jQuery is defined
var image = $('img');
image.on('load', function() {
console.log('seems like the image is loaded!');
});
image.on('error', function() {
console.log('bummer! image cannot be loaded!');
@twokul
twokul / hidden-classes-in-js-and-inline-caching.md
Last active April 23, 2024 22:02
Hidden classes in JavaScript and Inline Caching

Hidden classes in JavaScript and Inline Caching

Knowing how internals work is always a good. Pretty much for everything. Cars, trains, computers, you name it. It gives you an insight on what happens under the hood. You also act/react differently based on this knowledge.

As you might have guessed, it’s also true for web development. Knowledge of CSS transitions allows you to achieve better performance and not to use JavaScript in most cases. Knowledge of V8 internals allows you to write more performant JavaScript code. So let’s talk about V8 a little.

A little about V8

V8 is a JavaScript engine built by Google. Firefox built SpiderMonkey, Opera built Carakan and Microsoft built Chakra. One very important difference between V8 and other JavaScript engines is that V8 doesn’t generate any intermediate code. It compiles JavaScr

desc "Compile all the assets named in config.assets.precompile"
task :precompile do
# We need to do this dance because RAILS_GROUPS is used
# too early in the boot process and changing here is already too late.
if ENV["RAILS_GROUPS"].to_s.empty? || ENV["RAILS_ENV"].to_s.empty?
ENV["RAILS_GROUPS"] ||= "assets"
ENV["RAILS_ENV"] ||= "production"
Kernel.exec $0, *ARGV
else
Rake::Task["environment"].invoke
@twokul
twokul / usa_topo.json
Created October 23, 2013 20:38
usa topojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@twokul
twokul / cp.js
Created September 5, 2013 18:14
cp-set
App.Person = Ember.Object.extend({
firstName: null,
lastName: null,
fullName: function(key, value, oldValue) {
// setter
if (arguments.length > 1) {
var nameParts = fullNameString.split(/\s+/);
this.set('firstName', nameParts[0]);
this.set('lastName', nameParts[1]);
}
App.AjaxObject = Ember.Object.create({
value: function() {
// makes an ajax call to get new value
return service.getValue();
}.property().volatile()
});
$('<span></span>').css({display:'none',whiteSpace:'nowrap'}).appendTo($('body')).text('U. S. Government Accountability Office, http:// www.gao.gov').width()