Skip to content

Instantly share code, notes, and snippets.

View asci's full-sized avatar
🍊

Artem R asci

🍊
View GitHub Profile
@asci
asci / utest.js
Created August 9, 2012 14:04
Simple unit test
var code = function(num1, num2) {
// Сложная логика с предсказуемым результатом:
return num1 + num2;
}
var test = function (func, args, result) {
var res = func.apply(this, args);
if (res != result) {
console.log('FAIL, expected: ' + result + ', recieved ' + res);
} else {
@asci
asci / modelseq.as
Created September 12, 2012 08:36
Сравнение моделей
// Если модели не равны — возвращается false
public static function isModelAndDataEquals(model:BaseModel, data:*):Boolean {
var res:Boolean,
i:int;
for (var prop:String in model) {
if (model.hasOwnProperty(prop)) {
if (data.hasOwnProperty(prop)) {
// Если модель
if (model[prop] is BaseModel) {
res = BaseModel.isModelAndDataEquals(model[prop], data[prop]);
@asci
asci / gist:3775083
Created September 24, 2012 09:16
check
private function isProductSlotModelChangeKeyProperties(model:ProductionSlotModel):Boolean {
var index: int = getSlotViewIndexBySlotModel(_slots, model);
var slot:* = _slots[index];
var result:Boolean = false;
if (model.locked){
if (model.ready_for_open){
result = slot is SerialProductionSlotViewLockedReady;
if (!result) return true;
} else {
/**
* Created with JetBrains WebStorm.
* User: artem
* Date: 10.01.13
* Time: 21:34
* To change this template use File | Settings | File Templates.
*/
var mysql = require('mysql'),
Promise = require("promise").Promise;
<html><head><title>JBoss Web/7.0.13.Final - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>javax.servlet.ServletException: Servlet.init() for servlet spring th
var db = [];
var maxCount = 573;
var neibourghsCount = 50;
for (var i = 0; i < maxCount; i++) {
db[i] = {
name: 'user' + i,
id: i,
exp: Math.round(Math.random() * 10000),
points: Math.round(Math.random() * 100000)
@asci
asci / gist:5609188
Last active December 17, 2015 12:19
var Validator = (function (){
var rules = [];
return {
_add: function (rule) {
if (rules[rule.objectName] === undefined) {
rules[rule.objectName] = [];
}
rules[rule.objectName].push(rule);
},
configurate: function (rules) {
@asci
asci / contactsapp.js
Created October 18, 2013 21:23
JSON Driven Development
var app = {
name: 'Contact list',
version: '0.1',
db: 'mysql',
transports: ['http', 'websocket'],
auth: {
controllers: 'Contact',
types: {
vk: {
appCode: 1231341,
// Block
BN
.decl('main-page', 'mod', 'val') // mod and val are optional, but maybe we should prohibit modifications for javascript and use it only as CSS\DOM states
.deps('page', 'content') // Maybe depricated
.extends('page', 't-block') // Multiple inheritance: for data and view - complicate, for methods - override
// Initial code, e.g. for pages router - runs after block been declarated. alt names - 'runs', 'runAfterDecl'
.init(function () {
var inst = {
name: 'custom name',
init: function () {
var _this = this;
$('body').on('click', function () {
_this.getName(); // переменная _this берется из замыкания
});
},
getName: function () {
console.log(this.name);