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 | |
$breakpoint = time() - 3 * 30 * 24 * 60 * 60; | |
$q = db_select('node'); | |
$q->addField('node', 'nid'); | |
$q->addField('node', 'vid'); | |
$q->condition('comment', 2); | |
$q->condition('type', 'article'); | |
$q->condition('created', $breakpoint, '<'); |
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 formatNumber(value) { | |
var input = value.toString(), | |
inputParts = input.split('.'), | |
int = inputParts[0], | |
decimals = inputParts.length > 1 ? '.' + inputParts[1] : '', | |
output = []; | |
while (int.length > 3) { | |
output.unshift(int.substr(-3)); | |
int = int.substr(0, int.length - 3); |
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
class ApplicationController < ActionController::Base | |
... | |
# Redirect all requests to SSL. We use this rather than config.force_ssl since | |
# we want to use temporary rather than permanent redirects. | |
if Rails.env.production? | |
before_filter do |controller| | |
controller.force_ssl_redirect({:status => :found}) # 302: Moved temporarily | |
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
/** | |
* Track an event in Google Analytics (legacy or Universal). | |
* | |
* @param category | |
* The event category, e.g. "Download". | |
* @param action | |
* The event action, e.g. "PDF". | |
* @param label | |
* The event label, e.g. "Myfile.pdf". | |
* @param value |
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
require 'formula' | |
class Xhprof <Formula | |
url 'https://github.com/facebook/xhprof.git' | |
homepage 'http://mirror.facebook.net/facebook/xhprof/doc.html' | |
version 'master' | |
depends_on 'pcre' | |
def install |
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 | |
/** | |
* Calculate a unique integer based on two integers (cantor pairing). | |
*/ | |
function cantor_pair_calculate($x, $y) { | |
return (($x + $y) * ($x + $y + 1)) / 2 + $y; | |
} | |
/** |
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
... | |
# Use Swedish as default locale. | |
config.i18n.default_locale = :sv | |
... |
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 mymodule_init() { | |
drupal_set_message('A test message.', 'status'); | |
drupal_set_message(str_repeat('Another message. ', 10), 'status'); | |
drupal_set_message('A test warning.', 'warning'); | |
drupal_set_message('A test error!!!', 'error'); | |
} |
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
/** | |
* Helper function to link term names to taxonomy terms, and create new terms | |
* on-the-fly when necessary. | |
* | |
* @param $name | |
* - The name of the taxonomy term. | |
* @param $vocabulary_name | |
* - The machine name of the vocabulary where the term should be stored. | |
* @param $parent_name | |
* - Optionally the name of the parent term. |
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
# Remove whitespace and special characters and replace with dashes (-). | |
def self.filename(input) | |
input.split(%r{ |!|/|:|&|-|$|,|\?|%|\(|\)}).map { |i| i.downcase if i != '' }.compact.join('-') | |
end | |
# Convert to ascii and replace non-ascii letters. | |
def self.transliterate(input) | |
replacements = { | |
'å' => 'a', | |
'ä' => 'a', |