fixin (fixin) wrote,
fixin
fixin

Примеры моего кода на разных языках.

Си, утилита для конвертаци звуковых файлов из RCWV в WAV, 2008 год:

[Spoiler (click to open)]
// =============================================================
// (-C) Fixin aka Genius Of 1s, 2008
// =============================================================
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <io.h>
#include <sys\stat.h>
#define UNICODE
#include "windows.h"
char TranslateChar(char c1, char c2) {
char r;
//char str_src[2];
//char str_res[2];
WCHAR chSrc;
((char *) &chSrc)[0] = c1;
((char *) &chSrc)[1] = c2;
//WideCharToMultiByte(CP_ACP, 0, &chSrc, 1, &r, 1, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, &chSrc, 1, &r, 1, NULL, NULL);
//str_src[1]=0;
//str_src[0]=r;
//OemToAnsiBuff(&r, &r, 1);
//OEMToAnsi(str_src, str_res);
//r = str_res[0];
//printf("Convert: %x %x -> %c \n", c1, c2 ,r);
if (r==0) r=' ';
return r;
}
int main(int argc, char *argv[]) {
char MajorVersion=0;
char MinorVersion=0;
char Revision=0;
FILE* FromHandle;
FILE* ToHandle;
long BytesCopied;
int ccode;
int i;
char call_number[1024];
char call_name[1024];
char ch;
char dst_name[2000];
char a[100];
char prev = 0;
char fch = 0;
char buffer[6]; //6 symbols
int fl_media=0;
int fl_len =0;
printf("1800Message.com file format RCWV converter by Fixin 2008, http://fixin.com.ru ICQ:203-136-830, fixin@mail.ru\n");
printf("Supports UTF encoding in contact name\n");
printf("Free dotationware, WebMoney: Z667446785248, R883290290994 \n\n");
if(argc < 2) {
printf("You must specify a source file name!\nExample: rcwv myfile.rcwv\nThis converts file \"myfile.rcwv\" to \"myfile;AbonentName;AbonentNumber.wav\"");
return 1;
}
if ((FromHandle = fopen(argv[1], "rb")) == NULL)
{
printf("Cannot open source file: %s\n ", argv[1]);
return 1;
}
int pos_fn_beg=0;
int pos_fn_end=0;
int path_len=0;
int dst_len = 0;
pos_fn_end = strlen(argv[1])-1;
for (i = 0; i < strlen(argv[1]); i ++) {
if (argv[1][i] == '\\' || argv[1][i] == '/' || argv[1][i] == ':') {
pos_fn_beg = i+1;
path_len = i+1;
}
if (argv[1][i] == '.')
pos_fn_end = i-1;
dst_name [i] = argv[1][i];
}
printf("Src file:\"%s\" Path len: %i Pos beg: %i Pos end: %i\n", argv[1], path_len, pos_fn_beg, pos_fn_end);
//copy path to result name
for (i = 0; i < path_len; i ++)
dst_name[dst_len++] = argv[1][i];
int pos = 0;
int pos_b = 0, pos_c = 0, pos_d = 0;
while (1) {
ch=fgetc(FromHandle);
if (feof(FromHandle)) break;
buffer[5]=buffer[4];
buffer[4]=buffer[3];
buffer[3]=buffer[2];
buffer[2]=buffer[1];
buffer[1]=buffer[0];
buffer[0]=ch;
//Check position C
if (
buffer[0] == 'c' &&
(pos == 23)
){
pos_c = pos;
printf("Find pos C (abonent name): %i, filename size = %i\n", pos_c, dst_len);
//dst_name[dst_len++]=';'; //Add space
}
//Waiting for block d
/* if (
(buffer[0] == 'd') &&
(buffer[1] == 0) &&
(buffer[2] == 0) &&
(buffer[3] == 0) &&
pos_d == 0){
pos_d = pos;
printf("Find pos D (phone number): %i filename size = %i \n", pos_d, dst_len);
dst_name[dst_len++]='#'; //Add space
}
*/
//Read block c
if ((pos_c>0) && ((pos - pos_c) % 2 == 0) && (pos > pos_c)) {
if (
(buffer[0] == 0) &&
(buffer[1] == 0)) {
pos_d = pos+1;
printf("Find pos D (phone number): %i filename size = %i \n", pos_d, dst_len);
dst_name[dst_len++]=';'; //Add space
pos_c = -1;
} //Finish of block C
else {
fch =  TranslateChar(buffer[1], buffer[0]);
dst_name[dst_len++]=fch;
printf("Pos c : %i ->  %i = %x %x : %c \n", pos, pos_c, buffer[1], buffer[0], fch);
}
}
//printf("Pos , dst_name  : %pos ->  %s ", pos, dst_name);
//Read block d
if ((pos_d>0) && ((pos - pos_d) % 2 == 0) && (pos > pos_d)) {
if (
(buffer[0] == 0) &&
(buffer[1] == 0)) { pos_d = -1; } //Finish of block D
else {
fch =  TranslateChar(buffer[1], buffer[0]);
printf("Pos d : %i ->  %i = %x %x : %c \n", pos, pos_d, buffer[1], buffer[0], fch);
dst_name[dst_len++]=fch;
}
}
if (dst_len == 1000) {
if (!fl_len) {
printf("File name length so long, more then 1000 symbols, so truncate! \n");
fl_len = 1;
}
else
dst_len --;
}
if (
(buffer[0] == 'F') &&
(buffer[1] == 'F') &&
(buffer[2] == 'I') &&
(buffer[3] == 'R') && fl_media ==0){
fl_media = 1;
dst_name[dst_len++]=';'; //Add space
//Add source filename
for (i = pos_fn_beg; i <= pos_fn_end; i ++)
dst_name[dst_len++] = argv[1][i];
//Add extension WAV
dst_name[dst_len++] = '.';
dst_name[dst_len++] = 'w';
dst_name[dst_len++] = 'a';
dst_name[dst_len++] = 'v';
dst_name[dst_len++] = 0;
dst_name[dst_len++] = 0;
if ((ToHandle = fopen(dst_name, "wb")) == NULL) {
printf("Can'not open destination file: %s \n", dst_name);
return 1;
}
putc('R', ToHandle);
putc('I', ToHandle);
putc('F', ToHandle);
putc('F', ToHandle);
printf("Write to dst file: %s \n", dst_name);
}
else
if (fl_media == 1) {
putc(ch, ToHandle);
}
pos++;
}
fclose(FromHandle);
fclose(ToHandle);
return 0;
}


На Дельфи программка для сравнения прайсов 2002:
[Spoiler (click to open)]
unit PriceMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, Grids, DBGrids, ADODB, ToolWin, ComCtrls, dbcgrids,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
TreeViewPrice: TTreeView;
StatusBar1: TStatusBar;
DataSourcePrice: TDataSource;
ADOConnectionPrice: TADOConnection;
ADOTablePrice: TADOTable;
ADOQueryGroups: TADOQuery;
DataSource1: TDataSource;
ADOTablePriceNAME: TStringField;
ADOTablePriceCAR: TStringField;
ADOTablePricePRICE: TFloatField;
ADOTablePriceREST: TFloatField;
ADOTablePriceORDER: TFloatField;
ADOTablePriceARTICUL: TFloatField;
Panel1: TPanel;
ButtonAnalogs: TButton;
ButtonOrder: TButton;
EditOrder: TEdit;
Label1: TLabel;
EditSearch: TEdit;
procedure ToolButtonSelectFilterClick(Sender: TObject);
procedure TreeViewPriceDblClick(Sender: TObject);
procedure ButtonAnalogsClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
procedure DBGrid1ColExit(Sender: TObject);
procedure ADOTablePriceAfterScroll(DataSet: TDataSet);
procedure ButtonOrderClick(Sender: TObject);
private
{ Private declarations }
sFilterByArticul:String;
sQuick:String;
sSearch:String;
procedure SelectNode(Node:TTreeNode);
procedure BuildTree;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ToolButtonSelectFilterClick(Sender: TObject);
var
    sql:TStrings;
begin
    ADOTablePrice.Filter :='GROUP="Гайки"';
    ADOTablePrice.Filtered:=True;
    //sql.create;
    //sql.Add('SELECT * FROM PRICE WHERE GROUP="Гайки"');
    //ADOQueryPrice.SQL[0]:='SELECT * FROM PRICE WHERE GROUP=''Гайки''';
    //ADOQueryPrice.Active:=true;
end;
procedure TForm1.TreeViewPriceDblClick(Sender: TObject);
begin
SelectNode(TreeViewPrice.Selected);
end;
procedure TForm1.BuildTree;
var
NodeRoot,NodeCurr:tTreeNode;
sGroup,sPrevGroup:String;
sSubGroup:String;
begin
with ADOQueryGroups do
Begin
First;
NodeRoot:=TreeViewPrice.Items.GetFirstNode;
NodeCurr:=NodeRoot;
TreeViewPrice.Items.Clear;
sPrevGroup:='';
while not EOF do
Begin
    sGroup:=ADOQueryGroups['Group'];
    sSubGroup:=ADOQueryGroups['Producer'];
    if sGroup<>sPrevGroup then
    begin
      NodeCurr:=TreeViewPrice.Items.Add(NodeRoot,sGroup);
    end;
    TreeViewPrice.Items.AddChild(NodeCurr,sSubGroup);
    sPrevGroup:=sGroup;
    Next;
end;
end;
end;
procedure TForm1.SelectNode(Node:TTreeNode);
var
sFilter:String;
begin
with ADOTablePrice do
begin
if Node.Level=1 then
  sFilter:=
    '(PRODUCER='''+Node.Text+''')'+
    ' AND (GROUP='''+Node.Parent.Text+''')'
else
  sFilter:=
    '(GROUP='''+Node.Text+''')';
Filter:=sFilter;
Filtered:=True;
end
end;
procedure TForm1.ButtonAnalogsClick(Sender: TObject);
var
sFilter,sField:String;
FieldCur:TField;
Bmk:TBookmark;
begin
Bmk:=ADOTablePrice.GetBookmark;
if sFilterByArticul='' then
begin
sFilterByArticul:=ADOTablePrice.Filter;
FieldCur:=ADOTablePrice.Fields.FieldByName('ARTICUL');
if FieldCur.IsNull then
  sField:='0'
else
  sField:=FieldCur.AsString;
sFilter:='ARTICUL=''' +sField +'''';
end
else
begin
sFilter:=sFilterByArticul;
sFilterByArticul:='';
end;
with ADOTablePrice do
begin
Filter:=sFilter;
Filtered:=True;
end;
if ADOTablePrice.EOF then
begin
sFilter:=sFilterByArticul;
with ADOTablePrice do
begin
  Filter:=sFilter;
  Filtered:=True;
  GotoBookmark(Bmk);
end;
sFilterByArticul:='';
MessageBox(0,'Аналогов нет','Ошибка',MB_ICONEXCLAMATION);
end
end;
procedure TForm1.FormCreate(Sender: TObject);
var
NodeRoot:TTreeNode;
path:string;
begin
Path:=Application.ExeName;
Path:=copy(path,1,Length(Path)-Length('price.exe'));
ADOConnectionPrice.Connected:=False;
ADOConnectionPrice.ConnectionString:=
'Provider=MSDASQL.1;'+
'Persist Security Info=False;'+
'Data Source=Файлы dBASE;'+
'Extended Properties="'+
'DSN=Файлы dBASE;'+
'DBQ='+Path+';'+
'DefaultDir='+Path+';'+
'DriverId=533;'+
'MaxBufferSize=2048;'+
'PageTimeout=5;";'
+'Initial Catalog='+Path+'';
ADOConnectionPrice.Connected:=True;
ADOQueryGroups.Active:=True;
ADOTablePrice.Active:=True;
BuildTree;
NodeRoot:=TreeViewPrice.Items.GetFirstNode;
SelectNode(NodeRoot);
sFilterByArticul:='';
sSearch:='';
end;
procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
var
FieldIndex:Integer;
FieldName:String;
sSearch1:String;
V:Variant;
begin
try
if Key=Chr(8) then
sSearch1:=Copy(sSearch,1,Length(sSearch)-1)
else
begin
sSearch1:=sSearch+String(Key);
FieldIndex:=DBGrid1.SelectedIndex; //Индекс текущего выбранного поля
if FieldIndex<>-1 then
begin
  FieldName:=DBGrid1.Fields[FieldIndex].FieldName;
  V:=VarArrayOf([sSearch]);
  if ADOTablePrice.Locate(FieldName,sSearch1, [loPartialKey,loCaseInsensitive ]) then
  begin
    sSearch:=sSearch1;
    EditSearch.Text:=sSearch;
    //PanelSearch.Visible:=True;
  end
end
  //loCaseInsensitive,
end;
except
end;
end;
procedure TForm1.DBGrid1ColExit(Sender: TObject);
begin
sSearch:='';
EditSearch.Text:='';
end;
procedure TForm1.ADOTablePriceAfterScroll(DataSet: TDataSet);
begin
sSearch:='';
EditSearch.Text:='';
end;
procedure TForm1.ButtonOrderClick(Sender: TObject);
begin
EditOrder.Visible:=True;
EditOrder.Text:='1';
end;
end.


На PHP защитный код Тьюринга (2005):

[Spoiler (click to open)]
//fixin.ru TURING MOD
$turing_test = ( !empty($HTTP_POST_VARS['turing_test']) ) ? trim($HTTP_POST_VARS['turing_test']) : '';
/*if (need_turing_test($userdata))
{
//Count of messages
log_message("NEED TURING TEST");
$LIMIT_PERIOD=3600*1;
$LIMIT_PER_HOUR=$LIMIT_PERIOD/3600;
$LIMIT_USER_POSTS=10;
$LIMIT_USER_TOPICS=2;
$LIMIT_ANONYMOUS_POSTS=10;
$LIMIT_ANONYMOUS_TOPICS=4;
$count_posts=get_stats_per_hour("", $userdata['user_id'], $LIMIT_PERIOD, "POST") ;
$count_topics=get_stats_per_hour("", $userdata['user_id'], $LIMIT_PERIOD, "TOPIC");
if ($userdata['user_id']==ANONYMOUS)
{
$limit_posts=$LIMIT_ANONYMOUS_POSTS;
$limit_topics=$LIMIT_ANONYMOUS_TOPICS;
}
else
{
$limit_posts=$LIMIT_USER_POSTS;
$limit_topics=$LIMIT_USER_TOPICS;
}
log_message("CHECK LIMITS: POSTS $count_posts FROM $limit_posts  && TOPICS $count_topics FROM $limit_topics");
if ($count_posts>=$limit_posts)
log_and_die("To many posts $count_posts, you can only $limit_posts posts per $LIMIT_PER_HOUR hours");
if ($count_topics>=$limit_topics)
log_and_die("To many topics $count_topics, you can only  $limit_topics posts per $LIMIT_PER_HOUR hours");
$ss_turing_test=strtoupper(trim(set_turing_test($userdata,true)));
if (strstr($ss_turing_test, "####")) {
log_message("FIND #### TRYING TO HACK TURING TEST");
message_die(GENERAL_MESSAGE, 'Ssory, maybe you Hacker or Bot, you try to find turing code... 3 times errors' );
}
$ss_turing_test=str_replace("#","",$ss_turing_test);
$turing_test=strtoupper(trim($turing_test));
log_message("COMPATE TURING TESTS BASE: $ss_turing_test && USER:$turing_test");
if ($ss_turing_test!=$turing_test) {
//message_die(GENERAL_MESSAGE, 'Sorry, anonimus, you enter note valid code :' . $turing_test . " but " . trim($userdata['turing_test']));
if (trim($turing_test)=='') {
log_message("ENTERED EMPTY TURING TEST");
message_die(GENERAL_MESSAGE, 'Sorry, anonimus, you must enter 3-digit-code to post a reply or new topic' );
}
else {
log_message("ENTERED NOT VALID TURING TEST CODE");
message_die(GENERAL_MESSAGE, 'Sorry, anonimus, you enter note valid code :' . $turing_test );
}
}
}*/
//fixin.ru TURING MOD END
//fixin.ru QUOTE MOD BEGIN
do {
$matches=array();
ereg('\[quote.*\].*(\[quote.*\]).*\[/quote\]', $message, $matches);
$replace_part=trim($matches[1]);
if (trim($replace_part)<>'') //Subpattern
{
$message=str_replace($replace_part,"",$message);
}
}
while ($replace_part);
//fixin.ru QUOTE MOD END
//fixin.ru ANONIMUS IMAGES MOD
if ($userdata['user_id'] == ANONYMOUS)
{
if (strstr($message, "[img]"))
log_and_die('Sorry, anonimus, you must be registered user to puts IMAGES here, press "BACK"');
}
//fixin.ru ANONIMUS IMAGES MOD END
Tags: программирование, ручки
Subscribe
promo fixin december 31, 2037 16:57 1417
Buy for 30 tokens
UPD: Друзья, в августе 2019 года блог переехал на http://fixinchik.ru. Welcome! Добро пожаловать в журнал Осипова Сергея Александровича, известного также как Fixin и Гений 1С. Рекомендую ознакомиться с Часто Задаваемыми Вопросами обо мне. Что я хочу в подарок - список. Мой проект "…
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 39 comments