- 1
- 2
- 3
- 4
- 5
function get_field_by_id($tbl,$field,$id){ //получить field по id
$res=mysql_query($v="SELECT * FROM $tbl where `id`=$id");
$rez=mysql_fetch_array($res);
return $rez["$field"];
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+174
function get_field_by_id($tbl,$field,$id){ //получить field по id
$res=mysql_query($v="SELECT * FROM $tbl where `id`=$id");
$rez=mysql_fetch_array($res);
return $rez["$field"];
}
+164
function prepare_graph_query($query, $date_column, $date_format="%b %d") {
$date_format = empty($date_format) ? "%Y %b" : $date_format;
//...
}
+157
function utf8win1251($s){
$out=""; $c1=""; $byte2=false;
for ($c=0;$c<strlen($s);$c++){
$i=ord($s[$c]); if ($i<=127) $out.=$s[$c];
if ($byte2) { $new_c2=($c1&3)*64+($i&63); $new_c1=($c1>>2)&5;
$new_i=$new_c1*256+$new_c2;
if ($new_i==1025) $out_i=168; else
if ($new_i==1105) $out_i=184; else $out_i=$new_i-848;
$out.=chr($out_i); $byte2=false; }
if (($i>>5)==6) {$c1=$i;$byte2=true; } }
return $out; }
Я ничо не понял, но это круто.
http://letopisi.ru/index.php/Знаете-ли-что%3F_скрипт
−104
def entities(model, params = {})
@entities ||= {}
@entities[model] ||= []
if @entities[model].blank? or parameters_changed?(model, params)
@entities[model] = []
include = params[:include] || nil
group = params[:group] || nil
order = params[:order] || nil
page = params[:page] || nil
entity_ids = []
model_role = nil
model_class = model.to_s.classify.constantize
if self.has_role_for?(model_class)
self.roles_for(model_class).uniq.each do |role|
if role.authorizable_id.blank?
raise "Authorization problem! Found more than one #{model_class} model permission!" unless model_role.blank?
model_role = role.name
next
end
if !role.authorizable_id.blank? && MerchantRole::MERCHANT_ROLES.include?(role.name)
entity_ids << role.authorizable.id
end
end
if entity_ids.blank? and MerchantRole::MERCHANT_ROLES.include?(model_role)
#WARNING! RECURSION! EVIL!
if MerchantRole.has_entity_parent?(model)
parent_model = MerchantRole.entity_parent(model)
parent_entities = self.entities(parent_model)
unless parent_entities.blank?
_params = {
:conditions => conditions_and_parameters(params, nil, ["`#{model.to_s}`.`#{parent_model.to_s.singularize}_id` IN (?)", parent_entities.map(&:id)]),
:include => include,
:order => order,
:group => group
}
_params.merge!(:page => page) if params.keys.include?(:page)
if block_given?
(self.is_reseller? ? self.reseller.send(model) : model_class).each(_params) do |o|
yield o
end
else
@entities[model] = (self.is_reseller? ? self.reseller.send(model) : model_class).send(params.keys.include?(:page) ? :paginate : :find, :all, _params)
end
end
else
_params = {
:conditions => conditions_and_parameters(params, nil),
:include => include,
:order => order,
:group => group
}
_params.merge!(:page => page) if params.keys.include?(:page)
if block_given? #Find only merchants associated with the reseller or all merchants if we are no reseller.
(self.is_reseller? ? self.reseller.send(model) : model_class).each(_params) do |o|
yield o
end
else
@entities[model] = (self.is_reseller? ? self.reseller.send(model) : model_class).send(params.keys.include?(:page) ? :paginate : :find, :all, _params)
end
end
else
_params = { :conditions => conditions_and_parameters(params, nil, ["`#{model.to_s}`.`id` IN (?)", entity_ids]),
:include => include,
:order => order,
:group => group }
_params.merge!(:page => page) if params.keys.include?(:page)
if block_given?
model_class.each(_params) do |o|
yield o
end
else
@entities[model] = model_class.send(params.keys.include?(:page) ? :paginate : :find, :all, _params)
end
end
end
end
entities[@model]
end
This method does the following (you guessed it, right?):
#Fetch entities for which we have a read permission.
#This is now it should work:
#1. : If we don't have any role on the model, we won't get anything.
#2a.: Check roles we have for whole model. If no role for whole model we can only fetch instances we have assigned.
#2b.: Check all instances we have a role for and store them.
#3a.: We have roles for instances -> Goto(#7)
#3b.: We have no instance roles but have a role for the whole model.
#4. : Check recusively if we have roles fro a parent model (channels -> merchants).
#5a.: If we have a parent role and got parent entities returned we only fetch instances belonging to the parent entities.
#6a.: If we have a parent role and got no entities back, then we won't get anything since we are not supposed to.
#7. : Get all instances based on our reseller or globally for the system.
+155
function otherString($str,$style)
{
$str=trim($str);
switch($style)
{
case 1: $str=strip_tags($str); $str=str_replace("\n",'<br />',$str); break;
case 2: break;
case 3: $str=strip_tags($str); $str=str_replace("\n",'',$str); $str=str_replace('<br />',"\n",$str); break;
case 4: $str=ereg_replace('(mailto:|mailto|http://|http:/|http:|http|ftp://|ftp:/|ftp:|ftp)','',$str);break;
case 5: $str=stripslashes($str); break;
case 6: $str=stripslashes($str); $str=strip_tags($str); break;
case 7: $str=strip_tags($str); break;
}
return $str;
}
web-based cms
+164
if(totalWidth1Part!=totalWidth2Part){
if(totalWidth1Part>totalWidth2Part){
if((totalWidth1Part - totalWidth2Part)>60){
if((totalWidth1Part - totalWidth2Part)>180){
...
−132
found_files()
{
if [ "$DAY_CONF" = 'all_last' ]; then
files=$( ls -1 "$FILEPATH" | grep "$FILE_PREFIX" | grep -v `date "$DATE_PREFIX"` )
fi
if [ "$DAY_CONF" = 'last' ]; then
if [ "`date +%d`" -eq '01' ]; then
case "`date +%m`" in
02|04|06|09|11 )
need_date=31;
;;
03 )
if [ -n "$( ls -1 "$FILEPATH" | grep "$FILE_PREFIX" | grep `date +%Y0229` )" ]; then need_date=29; else need_date=28; fi;
;;
* )
need_date=30;
;;
esac
if [ "`date +%m`" -eq '01' ]; then
need_month=12
need_date=31
need_year=$(( `date +%Y` - 1 ))
files=$( ls -1 "$FILEPATH" | grep "$FILE_PREFIX" | grep "$need_year$need_month$need_date" )
else
need_month=$((`date +%m` - 1 ))
files=$( ls -1 "$FILEPATH" | grep "$FILE_PREFIX" | egrep `date ${DATE_PREFIX%%%m*}[0]*$need_month$need_date` )
fi
else
need_date=$((`date +%d` - 1))
files=$( ls -1 "$FILEPATH" | grep "$FILE_PREFIX" | egrep `date ${DATE_PREFIX%%%d*}[0]*$need_date` )
fi
fi
if [ "$DAY_CONF" = 'today' ]; then
files=$( ls -1 "$FILEPATH" | grep "$FILE_PREFIX" | grep `date "$DATE_PREFIX"` )
fi
echo $files
}
Замечательная функция поиска файлов "за вчера". Находит файлы не только "за вчера".
Автор неизвестен.
−85
(1 if not i%2 else 2)
−116
BOOL levelClosed = YES;
if (indexPath.row == 0)
{
levelClosed = NO;
}
else
{
iPadLevelDescriptor *prevLvlDescription = [levels objectAtIndex:(indexPath.row-1)];
scoresObject *prevLevelScoresObject = [ScoresTableUIViewController loadScoresForLevel:[[prevLvlDescription properties] objectForKey:kiPadLevelName]];
if (prevLevelScoresObject != nil)
levelClosed = ![prevLevelScoresObject completed];
}
levelClosed = NO;
[cell setClosed:lvlClosed];
Закрыт ли уровень?..
−88
# -*- coding: utf-8 -*-
from Tkinter import *
import time
import random
import os
def init(): #Инициалиазия, переменная root, задаём размеры окна
global root, widthmin, widthmax, heightmin, heightmax, geometry
widthmin = 400
widthmax = 400
heightmin = 400
heightmax = 400
geometry = str(widthmax) + 'x' + str(heightmax)
root = Tk()
root.geometry(geometry)
root.minsize(width=widthmin,height=heightmin)
root.maxsize(width=widthmax,height=heightmax)
menu()
root.mainloop()
def menu(): #Меню игры. С любовью, кэп
global btSingle, btMulti, btSetting, btQuit
btSingle = Button(root, text="Singleplayer", command=singleplayer)
btSingle.pack(padx=15,pady=15)
btMulti = Button(root, text="Multiplayer", command=multiplayer)
btMulti.pack(padx=15,pady=15)
btSettings = Button(root, text="Settings", command=settings)
btSettings.pack(padx=15,pady=15)
btQuit = Button(root, text="Quit", command=quit)
btQuit.pack(padx=15,pady=15)
def singleplayer(): #Функции синглплеера
global root #Удалить после заполнения функции более полезной хренью
def multiplayer(): #Функции мультплеера
global root #Удалить после заполнения функции более полезной хренью
def settings(): #Настройки
global root #Удалить после заполнения функции более полезной хренью
def quit(): #Выход из игры
root.destroy ()
init()