Skip to content

Instantly share code, notes, and snippets.

View Imater's full-sized avatar
🏠
Working from home

Вецель Евгений Imater

🏠
Working from home
View GitHub Profile
@Imater
Imater / gist:d49fbb934f7ae028f2e9
Created November 7, 2014 11:17
Fletcher algorithm of controll summ
function calcFletcherSum(data) {
var length = data.length, i = 0, sum1 = 0xFF, sum2 = 0xFF;
while (length) {
var tlen = length > 21 ? 21 : length;
length -= tlen;
do {
var ch = data.charCodeAt(i++);
if (ch > 255) {
var ch2 = ch >> 8;
ch &= 0xFF;
@Imater
Imater / gist:6a0e9a71bec5040a0655
Created October 15, 2014 04:54
Mongo agregate and distinct
db.CommonHeaderRule.aggregate({$group: {_id: "$Titles", count: {$sum:1}}}, {$sort: {count:-1}})
db.AssortmentHeaderRule.count()
db.AssortmentHeaderRule.distinct("Title")
@Imater
Imater / gist:474aabda872be40e3945
Created October 1, 2014 10:23
test for cases in c#
using System;
using Ksnsi.Services.Validation.ColValidators;
using NUnit.Framework;
namespace Ksnsi.Services.Tests
{
[TestFixture]
internal class ColValidatorNumericTest
{
private IColValidator _validator;
@Imater
Imater / article.model.coffee
Created September 2, 2014 16:08
model definition in sequelize
Sequelize = require 'sequelize'
sequelize = Sequelize.sequelize
sequelize.define 'article',
title:
type: Sequelize.STRING
html:
type: Sequelize.STRING
@Imater
Imater / recieve.coffee
Created September 2, 2014 03:55
Receive from RabbitMQ queue
fib = (n) ->
# Do it the ridiculous, but not most ridiculous, way. For better,
# see http://nayuki.eigenstate.org/page/fast-fibonacci-algorithms
a = 0
b = 1
i = 0
while i < n
c = a + b
@Imater
Imater / send.coffee
Created September 2, 2014 03:55
Send to RabbitMQ queue
amqp = require("amqplib")
basename = require("path").basename
when_ = require("when")
defer = when_.defer
uuid = require("node-uuid")
# I've departed from the form of the original RPC tutorial, which
# needlessly introduces a class definition, and doesn't even
# parameterise the request.
n = undefined
@Imater
Imater / app.less
Created August 27, 2014 15:03
not selectable css
.not-selectable {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
@Imater
Imater / split.controller.coffee
Created August 26, 2014 11:33
First draft of resize html windows on layout
$(".resize-handle").on "mousedown", (e)->
left = $(this).prev('.layout-col')
right = $(this).next('.layout-col')
windowWidth = $(window).width()
oldLeft = left.width()/windowWidth*100;
oldRight = right.width()/windowWidth*100;
oldX = e.clientX
console.info 'start', oldLeft, oldRight
onMouseMove = (e) ->
offset = oldX - e.clientX
@Imater
Imater / testing_test.go
Created August 26, 2014 03:20
Table tests for go
package main
import (
"testing"
)
func TestAdd(t *testing.T) {
if add(2,3,4,5,6) != 20 {
t.Error("Bad test")
@Imater
Imater / first.go
Created August 25, 2014 15:36
varadic set argument
package main
import "fmt"
func add(a ...int) int {
sum := 0
for _, num := range a {
sum += num
}
return sum