Ускоряем запуск 1С (для разработчика) Олег Филиппов SET Temp=G:\Temp SET Tmp=G:\Temp start C:\Snegopat\core\starter.exe ----------------------------------------------------------------------------------------------------------------- Концепции моделирования MongoDb на примере разработки социальных игр Александр Календарев { "user_id" : 1, "nickname" : "Bob", "level" : 3, "pvp_level": 17 , "awards" : ["hero-I","gold star"] } {"greeting" : "Hello, world!"} >db.users.insert({"nick": "Иван Бровкин", "level":20, "pvp_level" : 621, "awards": ["Silver star","Hero"] }) >db.users.insert({"nick": "Иван Чёлкин", "level":25, "pvp_level" : 749, "awards": ["Silver star","Victory "] }) >db.users.insert({"nick": "Швейк", "level":25, "pvp_level" : 794, "awards": ["Gold star","Hero"] }) > db.users.insert({"nick": "Василий Теркин", "level":23, "pvp_level" : 659, "awards": ["Gold star","Victory"] }) >db.users.find(); {"nick": "Василий Теркин", "level":23, "pvp_level" : 659, "awards": [ "award": {"name":"Gold star", "rating": 10, "type": 1} , "award": {"name":"Victory", "rating": 7, "type": 1} }] } friend: {"nick":"Василий Теркин", "avatar": "27AE/271.jpg", " id" : ObjectId("52cc2462d47566cbb0e20ff6") } friend: {"nick":"Иван Ченкин", "avatar": "23EB/743.jpg"," id" : ObjectId("52cae653d47566cbb0e20fed") } { "_ id" : ObjectId("52cc2462d47566cbb0e20ff6") , "nick" :"Василий Теркин", "avatar" : "27AE/271.jpg", "weapon" : { "id" : 27, "power" : 127, "reserve" : 10 "experience" : 10 }, "position" : { "x" : 453, "y" : 74 }, } { "_ id" : ObjectId("52cc2462d47566cbb0e20ff6"), "nick" : "Василий Теркин", "avatar" : "27AE/271.jpg", "weapon" : { "id" : 27, "power" : 127, "reserve" : 10 "experience" : 10 }, "position" : { "x" : 453, "y" : 74 }, // ссылка на коллекцию документов с танками "tanks" : ObjectId("52cae653d47566cbb0e20fed") } ----------------------------------------------------------------------------------------------------------------- Меньше кода, больше дохода. Часть 2. Разработка back-end слоя Михаил Ушаков vCenter Single Sign-On server (SSO)10 (файл hibernate.cfg.xml) CREATE TABLE `Users` ( `Id` INT NOT NULL AUTO_INCREMENT, `Login` VARCHAR(100) NOT NULL, `FirstName` VARCHAR(100) NOT NULL, `LastName` VARCHAR(100) NOT NULL, `City` VARCHAR(100) NOT NULL, `Email` VARCHAR(100) NOT NULL, `PasswordHash` VARCHAR(1000) NOT NULL, `GroupMembershipMask` INT NOT NULL, `RegistrationDate` DATETIME NOT NULL, `Activated` BIT NOT NULL, `Avatar` BLOB NULL, `AvatarFileName` VARCHAR(260) NULL, CONSTRAINT `PK_UserId` PRIMARY KEY (`Id`) ) COLLATE='utf8_general_ci' ENGINE=InnoDB; package com.mushakov.uralsmessbauerportal.db.entities.users; import java.util.Date; public class User { public int getId() { return id; } public void setId(int id) { this.id = id; } public String getLogin() { return login; } public void setLogin(String login) { this.login = login; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getPasswordHash() { return passwordHash; } public void setPasswordHash(String passwordHash) { this.passwordHash = passwordHash; } public int getGroupMembershipMask() { return groupMembershipMask; } public void setGroupMembershipMask(int groupMembershipMask) { this.groupMembershipMask = groupMembershipMask; } public Date getRegistrationDate() { return registrationDate; } public void setRegistrationDate(Date registrationDate) { this.registrationDate = registrationDate; } public boolean getActivated() { return activated; } public void setActivated(boolean activated) { this.activated = activated; } public Byte[] getAvatar() { return avatar; } public void setAvatar(Byte[] avatar) { this.avatar = avatar; } public String getAvatarFileName() { return avatarFileName; } public void setAvatarFileName(String avatarFileName) { this.avatarFileName = avatarFileName; } private int id; private String login; private String firstName; private String lastName; private String city; private String email; private String passwordHash; private int groupMembershipMask; private Date registrationDate; private boolean activated; private Byte[] avatar = new Byte[0]; private String avatarFileName; } public interface IDatabaseManager { public boolean open(); public void close(); public TEntity getEntityObject (Class entityClass, TId id); public List getEntityObjectsList(Class entityClass); public boolean updateEntityObject(TEntity entityObject); public boolean addEntityObject(TEntity entityObject); public boolean deleteEntityObject(Class entityClass, TId id); } @InjectService("HibernateSessionManager") private HibernateSessionManager sessionManager; public class DatabaseManager implements IDatabaseManager { public boolean open() { // session we are getting from IoC session = sessionManager.getSession(); return true; } public void close() { sessionManager.commit(); } public TEntity getEntityObject (Class entityClass, TId id) { if(session != null && session.isOpen()) { try { TEntity entityObject = null; entityObject = (TEntity) session.get(entityClass, id); return entityObject; } catch(Exception any) { sessionManager.abort(); throw new UnknownError("An exception ↵occurred during reading object " + any.getMessage()); } } return null; } public List getEntityObjectsList (Class entityClass) { if(session != null && session.isOpen()) { try { List entityObjectsList = session.createCriteria(entityClass).list(); return entityObjectsList; } catch(Exception any) { sessionManager.abort(); throw new UnknownError("An exception occurred during reading list of objects " + any.getMessage()); } } return null; } public boolean updateEntityObject(TEntity entityObject) { if(session != null && session.isOpen()) { try { if(entityObject != null) return false; session.saveOrUpdate(entityObject); sessionManager.commit(); return true; } catch(Exception any) { sessionManager.abort(); throw new UnknownError("An exception occurred during updating object " + any.getMessage()); } } return false; } public boolean addEntityObject(TEntity entityObject) { if(session != null && session.isOpen()) { try { if(session.contains(entityObject)) return false; session.save(entityObject); return true; } catch(Exception any) { sessionManager.abort(); throw new UnknownError("An exception occurred during adding object " + any.getMessage()); } } return false; } public boolean deleteEntityObject(Class entityClass, TId id) { if(session != null && session.isOpen()) { try { Object entityObject = getEntityObject(entityClass, id); if(entityObject == null) return false; session.delete(entityObject); return true; } catch(Exception any) { sessionManager.abort(); throw new UnknownError("An exception occurred during deleting object " + any.getMessage()); } } return false; } private Session session; @InjectService("HibernateSessionManager") private HibernateSessionManager sessionManager; } binder.bind(IDatabaseManager.class, DatabaseManager.class); public class Users { public void onActivate() { databaseManager.open(); currentUser = new User(); servicesUsers = databaseManager.getEntityObjectsList(currentUser.getClass()); if(servicesUsers != null && servicesUsers.size() > 0) currentUser = servicesUsers.get(0); databaseManager.close(); } public void onActionFromDeleteUser(int id) { databaseManager.open(); databaseManager.deleteEntityObject(currentUser.getClass(), id); databaseManager.close(); } @Inject private IDatabaseManager databaseManager; @Property private List servicesUsers = new ArrayList(); @Property private User currentUser; }

Users management tools with CRUD!

View user
Update
Delete
@Inject private Logger logger; log4j.rootCategory=INFO, A1 log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=[%p] %c{1} %m%n log4j.category.org.apache.tapestry5.TapestryFilter=info log4j.category.org.apache.tapestry5=error log4j.category.tapestry5=error #### Second appender writes to a file log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=${catalina.home}/logs/testsecurity.txt # Control the maximum log file size log4j.appender.R.MaxFileSize=10MB # Archive log files (one backup file here) log4j.appender.R.MaxBackupIndex=1 log4j.appender.R.layout=org.apache.log4j.PatternLayout #log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n log4j.appender.R.layout.ConversionPattern=%p [%t] %d{dd MMM yyyy HH:mm:ss} (%F:%L) - %m%n ----------------------------------------------------------------------------------------------------------------- Ruby и многозадачность Иван Шихалев puts 'begin' th = Thread.new do (1..3).each { |i| puts i } end # sleep 0 puts '---' th.join puts 'end' th = Thread.new do puts 'started' Thread.stop puts 'continued' sleep 100 puts 'finished' end sleep 0.1 puts 'wakeup' th.wakeup sleep 0 puts 'terminate' th.terminate th.join Thread.new 1, 2, 3 { |a, b, c| ... } flag = true 5.times do Thread.new do puts 'true' if flag flag = false end end Thread.list.each do |th| if th != Thread.current th.join end end 5.times do Thread.new do Thread.exclusive do puts 'true' if flag flag = false end end end alpha = true alpha_m = Mutex.new beta = true beta_m = Mutex.new 5.times do Thread.new do alpha_m.synchronize do puts 'alpha' if alpha alpha = false end beta_m.synchronize do puts 'beta' if beta beta = false end end end th = Thread.new do sleep 0.1 p Thread.current.thread_variable_get 'alpha' end th.thread_variable_set 'alpha', :alpha th.join th = Thread.new do sleep 0.1 p Thread.current['alpha'] end th['alpha'] = :alpha th.join f = Fiber.new do current = Time.new loop do last = current current = Time.new Fiber.yield [last, current] end end 5.times do p f.resume sleep 1 end pid = fork do 3.times do |i| sleep 0.01 puts "Child [#{Process.pid}]: #{i}" end end 3.times do |i| sleep 0.01 puts "Parent [#{Process.pid}]: #{i}" end Process.waitpid pid spawn(‹env,› command ‹, args›*, ‹options›) → pid child = fork do count = 0 Signal.trap :USR1 do count += 1 puts "Signal USR1: #{count}" end Signal.trap :TERM do puts 'Signal TERM' exit end sleep 1000 puts 'Ooops!' end Signal.trap :CHLD do puts 'Child died.' end Process.kill :USR1, child sleep 0.01 Process.kill :USR1, child Process.kill :TERM, child Process.wait rd, wr = IO.pipe child = fork do rd.close wr.write 'From Child' wr.close end wr.close msg = rd.read rd.close p msg Process.wait rd, wr = IO.pipe child = spawn "echo 'External Child'", [ STDERR, STDOUT ] => wr wr.close msg = rd.read rd.close p msg Process.wait ----------------------------------------------------------------------------------------------------------------- Качество программного кода. От выявления стилистических огрехов к поиску ошибок Денис Силаков void CAST256::Base::UncheckedSetKey() { word32 kappa[8]; ... memset(kappa, 0, sizeof(kappa)); } $ valgrind kopete -----------------------------------------------------------------------------------------------------------------