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 | |
* @Route("/{id}/edit", name="user_edit") | |
* @Template() | |
*/ | |
public function editAction($id) | |
{ | |
/** @var $dm \Doctrine\ODM\MongoDB\DocumentManager */ | |
$dm = $this->get('doctrine_mongodb')->getManager(); |
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
{ | |
"name": "symfony/framework-standard-edition", | |
"description": "The \"Symfony Standard Edition\" distribution", | |
"autoload": { | |
"psr-0": { "": "src/" } | |
}, | |
"require": { | |
"php": ">=5.3.3", | |
"symfony/symfony": "2.2.*", | |
"twig/extensions": "1.0.*", |
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 | |
// hook_nodeapi | |
if ($op == 'presave') { | |
foreach ($node->field_reply as $key => $field) { | |
if (strpos($field['value'], '<!-- time:') === FALSE) { | |
$node->field_reply[$key]['value'] = $field['value'] . '<br /><!-- time: ' . date() . ' -->'; | |
} |
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 | |
$str = '<!doctype html> | |
<html lang="en-US"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<a href="http://km.ru">test</a> |
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 | |
$ttl = 5 * 3600; | |
$refresh_time_limit = strtotime('2013-04-07 13:00'); // variable_get | |
$limit = 10; // variable_get | |
$max_limit = 450; // variable_get | |
$now = time(); // 12:15 | |
$is_hour = ($now - $refresh_time_limit) > 3600; // true |
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
<iframe id="myIframe" src="" width="400" height="100" frameborder="0"></iframe> | |
<script type="text/javascript"> | |
var url = 'http://lenta.ru'; | |
document.getElementById('myIframe').src = url + '?p=' + Math.floor(Math.random() * 1000); | |
</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 | |
db_set_active('knigi'); | |
$result = db_query('SELECT nid FROM node where uid <> 0'); | |
$nids = array(); | |
while ($row = db_fetch_array($result)) { | |
$nids[] = $row['nid']; | |
} |
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
def combine_anagrams(words) | |
output = {} | |
words.each do |word| | |
index = word.downcase.chars.sort.join | |
output[index].is_a?(Array) ? output[index] << word : output[index] = [word] | |
end | |
output.values | |
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
def rps_game_winner(game) | |
raise WrongNumberOfPlayersError unless game.length == 2 | |
2.times do |i| | |
raise NoSuchStrategyError unless ['P', 'S', 'R'].include? game[i][1].upcase | |
end | |
first = game[0][1].upcase | |
second = game[1][1].upcase | |
if first == 'P' |
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
def palindrome?(str) | |
str.downcase.gsub(/\W/, '') == str.downcase.gsub(/\W/, '').reverse | |
end | |
def count_words(str) | |
words = {} | |
str.downcase.split(/\W+/).each do |word| | |
words[word] = words.include?(word) ? words[word] + 1 : words[word] = 1 | |
end | |
words |