+97
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
{$APPTYPE CONSOLE} {$IFDEF FPC}{$MODE DELPHI}{$ENDIF}
uses SysUtils, Classes, IniFiles, Variants;
type TGetToken = function(var p: pointer): LongInt;
procedure ParseData(var p: pointer; isKey: boolean); forward;
procedure AdvanceIndex(var i: LongInt); forward;
function GetIntegerToken(var p: pointer): LongInt;
var value: LongInt = 0;
negative: boolean;
begin
Inc(p);
negative := PByte(p)^ = ord('-');
if negative then Inc(p);
repeat
value := value * 10 + LongInt(PByte(p)^ - $30);
Inc(p)
until PChar(p)^ = 'e';
Inc(p);
if negative then value := - value;
Result := value
end;
function GetListToken(var p: pointer): LongInt;
var index: Integer = 0;
begin
Inc(p);
while PChar(p)^ <> 'e' do begin
AdvanceIndex(index);
ParseData(p, false);
end;
Inc(p);
Result := -1
end;
function GetDictToken(var p: pointer): LongInt;
begin
Inc(p);
while PChar(p)^ <> 'e' do begin
ParseData(p, true);
ParseData(p, false);
end;
Inc(p);
Result := -1
end;
function ParseError(var p: pointer): LongInt;
begin
Writeln('TYIIINTE CBET');
Result := -1;
Halt(Result)
end;
const FuncTable: array[0..3] of TGetToken = (ParseError, GetDictToken, GetIntegerToken, GetListToken);
function GetStringToken(var p: pointer): string;
var value: ShortString;
length: LongInt = 0;
begin
repeat
length := length * 10 + LongInt(PByte(p)^ - $30);
Inc(p)
until PChar(p)^ = ':';
if length in [1..255] then begin
PByte(p)^ := length;
Move(p^, value, length+1);
Result := value;
end else Result := 'BINARY DATA';
Inc(p, length + 1);
end;
var sl: TStringList;
outf: TIniFile;
procedure AdvanceIndex(var i: LongInt);
begin
sl.Add(IntToStr(i));
Inc(i);
end;
type TSaveData = procedure(value: Variant);
procedure SaveData(value: Variant);
var
key: string = '';
i: LongInt;
begin
for i := 0 to sl.Count - 1 do key := key + '.' + sl[i];
Delete(key, 1, 1);
outf.WriteString('Torrent', key, VarToStr(value));
if sl.Count > 0 then sl.Delete(sl.Count - 1);
end;
procedure PushKey(value: Variant);
begin
sl.Add(value)
end;
procedure PopKey(value: Variant);
begin
if sl.Count > 0 then sl.Delete(sl.Count - 1);
end;
procedure NOP(value: Variant);
begin
end;
const SaveDataTable: array[0..3] of TSaveData = (SaveData, PushKey, PopKey, NOP);
procedure ParseData(var p: pointer; isKey: boolean);
var
OpCode: ShortInt;
value: Variant;
begin
OpCode := PByte(p)^;
if OpCode >= $60 then value := FuncTable[OpCode shr 2 and 3](p)
else if Opcode in [$30..$39] then value := GetStringToken(p)
else ParseError(p);
SaveDataTable[ord(isKey) + 2*ord(chr(OpCode) in ['d', 'l'])](value);
end;
var f: TFileStream;
s: LongInt;
p, cp: pointer;
begin
if ParamCount <> 1 then Writeln('Usage: ', ParamStr(0), ' filename.torrent')
else
try
f := TFileStream.Create(ParamStr(1), fmOpenRead);
s:= f.Size;
GetMem(p, s + 1);
f.ReadBuffer(p^, s);
cp := p;
outf := TIniFile.Create(ChangeFileExt(ParamStr(1), '.ini'));
sl := TStringList.Create;
ParseData(cp, false);
finally
if sl <> nil then sl.Destroy();
if outf <> nil then outf.Destroy();
if p <> nil then FreeMem(p);
if f <> nil then f.Destroy()
end
end.
Парсер torrent-файлов и сохранялка в INI-файл (пока без сумм фрагментов). Опа-лаба-стайл, писано левой ногой анскильного питуха.
inkanus-gray,
09 Июля 2013
+139
- 1
- 2
- 3
- 4
- 5
#define InlineIsEqualGUID(rguid1, rguid2) \
(((unsigned long *) rguid1)[0] == ((unsigned long *) rguid2)[0] && \
((unsigned long *) rguid1)[1] == ((unsigned long *) rguid2)[1] && \
((unsigned long *) rguid1)[2] == ((unsigned long *) rguid2)[2] && \
((unsigned long *) rguid1)[3] == ((unsigned long *) rguid2)[3])
Windows SDK, guiddef.h
ret = InlineIsEqualGUID(&g_guid, guid_array + i); /* ??? */
serg_ik,
07 Июля 2013
+16
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
for(int i=0;i<World::size;i++)
{
for(int u=0;u<World::size;u++)
{
//Задаётся зерно для генерации случайных чисел
srand(GetTickCount()*i*u);
//Задаются случайные значения всем точкам от 0*0.1-10, до 100*0.1-10
World::data[i][u]=(rand()%100)*0.1f-10.0f;
}
}
http://habrahabr.ru/post/183986/
Abbath,
20 Июня 2013
−99
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- (void)initPlayerViewController
{
BOOL isSuccess = NO;
do {
NSString *linkString = nil;
unsigned long long objectID = [_videoID intValue];
int index = GetElementIndex(objectID, _WidevineTestStubs, WIDEVINE_TEST_COUNT);
if (index >= 0) {
//linkString = GetLink(_WidevineTestServers[index], _WidevineTestFiles[index]);
linkString = _WidevineTestLinks[index];
}
else {
linkString = GetString([_videoLink objectForKey:@"src"]);
}
if(linkString == nil)
goto _end;
self.linkType = GetLinkType(linkString);
switch (_linkType) {
case LINK_TYPE_HLS:
break;
case LINK_TYPE_WV_ADAPTIVE:
case LINK_TYPE_WV_MULTI:
linkString = WidevinePlay(linkString);
if ([linkString length] <= 0) {
goto _end;
}
break;
default:
goto _end;
}
NSURL *link = [NSURL URLWithString:linkString];
if(link == nil)
break;
self.playerViewController = [[[MPMoviePlayerViewController alloc] initWithContentURL:link] autorelease];
_playerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
_playerViewController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
NSInteger startPosition = GetInteger([_videoLink objectForKey:@"play_start_time"]);
if(startPosition > 0) {
_playerViewController.moviePlayer.initialPlaybackTime = (NSTimeInterval)startPosition;
}
[self addControlsView];
NSArray *audioTracks = [_videoLink objectForKey:@"audio_list"];
if ([audioTracks count] < 2) {
UIButton *audioButton = (UIButton *)[_controlsView viewWithTag:TAG_BUTTON_CHANGE_AUDIO];
audioButton.enabled = FALSE;
}
isSuccess = YES;
} while(0);
_end:
if(isSuccess) {
[_delegate onPlayerCreated:self];
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
}
else {
[_delegate onLinkError:self];
}
}
Тут есть все, и do while(0), и проваливающиеся case'ы, и TRUE/FALSE, и глобальные inline методы, и даже goto.
ArtFeel,
13 Июня 2013
+132
- 1
private static string TestExistFiles(ref int maxd, ref Hashtable executedgroups)
taburetka,
10 Июня 2013
+162
- 1
- 2
- 3
- 4
- 5
try {
die(@date("d.m.Y H:i:s") . "\t" . $this->x($id, true) . "\r\n");
} catch (Exception $e) {
die(@date("d.m.Y H:i:s") . "\tERROR: " . $e->getMessage() . "\r\n");
}
остаться в живых
Lure Of Chaos,
15 Мая 2013
+101
- 1
- 2
- 3
- 4
if(searchParams == null)
{
throw new NullReferenceException("параметры поиска = null" + searchParams.ToString());
}
Эдакий InnerException, чтоб верняково
NeoN,
01 Мая 2013
−102
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
@interface CORERatingImages : NSObject
{
UIImage *imageForOne;
UIImage *imageForTwo;
UIImage *imageForThree;
UIImage *imageForFour;
UIImage *imageForFive;
}
+(CORERatingImages *) ratingImages;
-(UIImage *) getRatingImage:(int) ratings;
@property (nonatomic, retain) UIImage *imageForOne;
@property (nonatomic, retain) UIImage *imageForTwo;
@property (nonatomic, retain) UIImage *imageForThree;
@property (nonatomic, retain) UIImage *imageForFour;
@property (nonatomic, retain) UIImage *imageForFive;
-(void) releaseResources;
@end
static CORERatingImages *ratingImages = nil;
@implementation CORERatingImages
@synthesize imageForOne;
@synthesize imageForTwo;
@synthesize imageForThree;
@synthesize imageForFour;
@synthesize imageForFive;
+(CORERatingImages *) ratingImages
{
@synchronized(self)
{
if (ratingImages == nil)
{
ratingImages = [[self alloc] init];
}
}
return ratingImages;
}
-(id) init
{
if (self = [super init])
{
self.imageForOne = [UIImage imageNamed:@"1.png"];
self.imageForTwo = [UIImage imageNamed:@"2.png"];
self.imageForThree = [UIImage imageNamed:@"3.png"];
self.imageForFour = [UIImage imageNamed:@"4.png"];
self.imageForFive = [UIImage imageNamed:@"5.png"];
}
return self;
}
-(UIImage *) getRatingImage:(int) ratings
{
if (ratings == 1)
{
return imageForOne;
}
else if (ratings == 2)
{
return imageForTwo;
}
else if (ratings == 3)
{
return imageForThree;
}
else if (ratings == 4)
{
return imageForFour;
}
else if (ratings == 5)
{
return imageForFive;
}
else
{
return [UIImage imageNamed:@"0.png"];
}
}
-(void) dealloc
{
NSLog(@"release Images");
[imageForOne release];
[imageForTwo release];
[imageForThree release];
[imageForFour release];
[imageForFive release];
[super dealloc];
}
-(void) releaseResources
{
[ratingImages release];
ratingImages = nil;
}
@end
Массив или stringWithFormat: @"%d.png"?
Не, не слышал.
QuickNick,
11 Апреля 2013
+156
- 1
- 2
- 3
- 4
- 5
$.post("include/show_watching.php",
function(data) {
$('#content').empty().append(data);
}
);
Вот такой вот POST-запрос.
Stallman,
26 Марта 2013