Skip to content

Instantly share code, notes, and snippets.

View gmrdad82's full-sized avatar
🎮
Gaming

Catalin Ilinca gmrdad82

🎮
Gaming
  • Castellon de la Plana, Spain
  • 22:14 (UTC +02:00)
  • YouTube @GmrDad82
View GitHub Profile
d1 = Date.parse('jan 1 2011')
d2 = Date.parse('dec 31 2012')
(d1..d2).map{ |m| m.strftime('%Y%m') }.uniq.map{ |m| Date::ABBR_MONTHNAMES[ Date.strptime(m, '%Y%m').mon ] + ' ' + m.first(4) }
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
from string import ascii_lowercase as lower, ascii_uppercase as upper, ascii_letters as both
# 1. Build a coder
def buildCoder(shift):
return dict(zip(both, (lower[shift:] + lower[:shift] + upper[shift:] + upper[:shift])))
# 2. Apply the coder
def applyCoder(text, coder):
return "".join([coder.get(letter, letter) for letter in text])
# 1. RectangularRoom
class RectangularRoom(object):
def __init__(self, width, height):
self.width, self.height = width, height
self.tiles = dict(((x, y), 0) for x in range(width) for y in range(height))
def cleanTileAtPosition(self, pos):
self.tiles[(int(pos.x), int(pos.y))] += 1
def isTileCleaned(self, m, n):
@gmrdad82
gmrdad82 / harlemshake.js
Created December 16, 2013 14:26
harlem shake
javascript:(function(){function c(){var e=document.createElement("link");e.setAttribute("type","text/css");e.setAttribute("rel","stylesheet");e.setAttribute("href",f);e.setAttribute("class",l);document.body.appendChild(e)}function h(){var e=document.getElementsByClassName(l);for(var t=0;t<e.length;t++){document.body.removeChild(e[t])}}function p(){var e=document.createElement("div");e.setAttribute("class",a);document.body.appendChild(e);setTimeout(function(){document.body.removeChild(e)},100)}function d(e){return{height:e.offsetHeight,width:e.offsetWidth}}function v(i){var s=d(i);return s.height>e&&s.height<n&&s.width>t&&s.width<r}function m(e){var t=e;var n=0;while(!!t){n+=t.offsetTop;t=t.offsetParent}return n}function g(){var e=document.documentElement;if(!!window.innerWidth){return window.innerHeight}else if(e&&!isNaN(e.clientHeight)){return e.clientHeight}return 0}function y(){if(window.pageYOffset){return window.pageYOffset}return Math.max(document.documentElement.scrollTop,document.body.scrollTop)}funct
@gmrdad82
gmrdad82 / index.html
Created December 18, 2013 14:30 — forked from neave/index.html
<!DOCTYPE html>
<html>
<head>
<style> body { margin: 0; } </style>
</head>
<body>
<canvas id="wobble"></canvas>
<script src="http://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5/dat.gui.min.js"></script>
<script src="wobble.js"></script>
</body>

Per-directory Bash history (w/o aliasing cd)

I use Bash’s PROMPT_COMMAND variable:

The value of the variable PROMPT_COMMAND is examined just before Bash prints each primary prompt. If PROMPT_COMMAND is set and has a non-null value, then the value is executed just as if it had been typed on the command line.

The source code should be pretty straight forward, but if not, please ask in the comments. Put this in your .bashrc or similar:

# per-directory Bash history
/**
* @example
* <span ng-html='foo.bar'></span>
*/
app.directive('ngHtml', function() {
return function(scope, element, attrs) {
scope.$watch(attrs.ngHtml, function(value) {
element[0].innerHTML = value;
});
}

Abstract

You could have postgre installed on localhost with password (or without user or password seted after instalation) but if we are developing we really don't need password, so configuring postgre server without password for all your rails project is usefull.

Install Postgre packages

  • postgresql
  • postgresql-client
  • libpq-dev
@gmrdad82
gmrdad82 / README.md
Last active August 29, 2015 14:13 — forked from peterdietz/README.md

Most instructions for using Capistrano tell you how to make it restart Phusion Passenger by 'touch'ing the restart.txt file, but this doesn't immediately restart the app - instead the first person to try to use the application will cause it to be restarted, so they will see a delay of at least a few seconds.

This shows how to add a post-deploy task to 'ping' the server, to cause it to restart immediately.

Then add a deploy:ping task to config/deploy.rb and set it to run automatically after deploy:restart. Alternatively you could put it into the deploy:restart task directly.

TODO: Test the response HTTP header of the ping, that it is a 200, and not some other error response (404/500).