Skip to content

Instantly share code, notes, and snippets.

View BlazPerus's full-sized avatar

Blaž Peruš BlazPerus

  • Ljubljana, Slovenia
View GitHub Profile
@necolas
necolas / snippet.js
Created June 14, 2011 20:36
Optimised async loading of cross-domain scripts
/*
* Updated to use the function-based method described in http://www.phpied.com/social-button-bffs/
* Better handling of scripts without supplied ids.
*
* N.B. Be sure to include Google Analytics's _gaq and Facebook's fbAsyncInit prior to this function.
*/
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
@sameera207
sameera207 / select_tag rails
Created March 22, 2012 18:51
Using selected option in rails select_tag
year array -> ['2012','2011','2010','2009']
selected year -> 2010
<%= select_tag 'year_range', options_for_select(['2012','2011','2010','2009'],'2010') %>
which will always selects '2010'
If you are selecting an object
@liamja
liamja / mixpanel.haml
Created April 23, 2012 18:04
Mixpanel HAML
/ start Mixpanel
%script
(function(d,c){var a,b,g,e;a=d.createElement("script");a.type="text/javascript";a.async=!0;a.src=("https:"===d.location.protocol?"https:":"http:")+'//api.mixpanel.com/site_media/js/api/mixpanel.2.js';b=d.getElementsByTagName("script")[0];b.parentNode.insertBefore(a,b);c._i=[];c.init=function(a,d,f){var b=c;"undefined"!==typeof f?b=c[f]=[]:f="mixpanel";g="disable track track_pageview track_links track_forms register register_once unregister identify name_tag set_config".split(" ");
for(e=0;e<g.length;e++)(function(a){b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,0)))}})(g[e]);c._i.push([a,d,f])};window.mixpanel=c})(document,[]);
mixpanel.init("TOKEN");
/ end Mixpanel
@mikhailov
mikhailov / 0. nginx_setup.sh
Last active December 26, 2022 19:30
Nginx + secure pseudo-streaming
# Nginx can serve FLV/MP4 files by pseudo-streaming way without any specific media-server software.
# To do the custom build we use 2 modules: --with-http_secure_link_module --with-http_flv_module
# This module "secure-link" helps you to protect links from stealing away.
#
# NOTE: see more details at coderwall: http://coderwall.com/p/3hksyg
cd /usr/src
wget http://nginx.org/download/nginx-1.5.13.tar.gz
tar xzvf ./nginx-1.5.13.tar.gz && rm -f ./nginx-1.5.13.tar.gz
@ouyangzhiping
ouyangzhiping / backup.md
Last active June 9, 2018 10:33
Backing Up PostgreSQL With Backup and Whatever Gems with Drobpbox api

create backup project

bundle exec backup generate:model --trigger my_backup --archives --storages='dropbox' --compressors='gzip' --notifiers='mail' --databases="postgresql"

dropbox api

https://www.dropbox.com/developers/apps

@logrusorgru
logrusorgru / gist:9867976
Last active December 16, 2022 02:54
Rails - How to check for online users? Redis.

Rails - How to check for online users? Redis.

Init Redis

   # config/initializers/redis.rb
    
   $redis_onlines = Redis.new
   # it's the simplest way, but i'd recommend:
   # $redis_onlines = Redis.new path: "/tmp/redis.sock", db: 15, driver: :hiredis
@Rich-Harris
Rich-Harris / service-workers.md
Last active July 10, 2024 17:04
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

@smks
smks / intl.js
Created November 12, 2016 19:07
Features of the Intl API
// Number Formatter
var communityPoints = 35000000.00;
var ukFormatter = new Intl.NumberFormat('en-uk');
var formattedNumber = ukFormatter.format(communityPoints);
console.log(formattedNumber);
// Currency formatter
var houseMaterialCosts = 120457.46;
var currencyFormatter = new Intl.NumberFormat('en-GB', { style: 'currency', currency: 'GBP' });
var formattedCosts = currencyFormatter.format(houseMaterialCosts);