This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # http://projecteuler.net/index.php?section=problems&id=25 | |
| # There are memoization libs, but i had it at my | |
| # fingertips anyway .. | |
| def memoize(name) | |
| cache = {} | |
| (class << self; self; end).send(:define_method, name) do |*args| | |
| cache[args] = super(*args) unless cache.has_key?(args) | |
| cache[args] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function t(f) { var x = (new Date()).getTime(); f.call(); return (new Date()).getTime() - x; } | |
| t(function() { for(i = 0; i < 1000000; ++i) { Math.ceil(i); } }); | |
| // 1081 | |
| t(function() { for(i = 0; i < 1000000; ++i) { ~~i; } }); | |
| // 772 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script type="text/javascript"> | |
| (function($) { | |
| $("body").load(function() { | |
| setTimeout(function() { | |
| var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | |
| ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | |
| var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | |
| }, 1); | |
| }); | |
| })(jQuery); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module CacheHelper | |
| # | |
| # Implements Google's "Leverage Proxy Caching" tip: | |
| # Instead of using a query parameter as cache buster - | |
| # encode it into the URL to ensure public proxies can | |
| # cache it too. | |
| # | |
| # NOTE: Activates in production mode only because it's | |
| # not necessary for development and needs a mod_rewrite | |
| # rule for Apache anyway: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Array.max = function(array){ | |
| return Math.max.apply(Math, array); | |
| }; | |
| Array.min = function(array){ | |
| return Math.min.apply(Math, array); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Spork.each_run do | |
| # This code will be run each time you run your specs. | |
| load "#{Rails.root}/config/routes.rb" | |
| Dir["#{Rails.root}/app/**/*.rb"].each { |f| load f } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @mixin background-rgba($r,$g,$b,$a) { | |
| // To mimic this in Internet Explorer, you can use the proprietary filter | |
| // property to create a gradient with the same start and end color, along | |
| // with an alpha transparency value. | |
| @if experimental-support-for-microsoft { | |
| $color: ie_hex($r,$g,$b,$a); | |
| $value: unquote("progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=##{$color},endColorstr=##{$color})"); | |
| background-color: transparent\9; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- Place this tag just before your close body tag and NOT in your <head> --> | |
| <script> | |
| (function(d, t) { | |
| var g = d.createElement(t), | |
| s = d.getElementsByTagName(t)[0]; | |
| g.async = true; | |
| g.src = 'https://apis.google.com/js/plusone.js'; | |
| s.parentNode.insertBefore(g, s); | |
| })(document, 'script'); | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // displays some comments for a certain url | |
| $url = 'http://developers.facebook.com/docs/reference/fql/comment/'; | |
| // fql multiquery to fetch all the data we need to display in one go | |
| $queries = array('q1' => 'select post_fbid, fromid, object_id, text, time from comment where object_id in (select comments_fbid from link_stat where url ="'.$url.'")', | |
| 'q2' => 'select post_fbid, fromid, object_id, text, time from comment where object_id in (select post_fbid from #q1)', | |
| 'q3' => 'select name, id, url, pic_square from profile where id in (select fromid from #q1) or id in (select fromid from #q2)', | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ssh-reagent () { | |
| for agent in /tmp/ssh-*/agent.*; do | |
| export SSH_AUTH_SOCK=$agent | |
| if ssh-add -l 2>&1 > /dev/null; then | |
| echo Found working SSH Agent: | |
| ssh-add -l | |
| return | |
| fi | |
| done | |
| echo Cannot find ssh agent - maybe you should reconnect and forward it? |