[offset] [type] [value] [description]
0000 32 bit integer 0x00000803(2051) magic number
0004 32 bit integer 60000 number of images
0008 32 bit integer 28 number of rows
0012 32 bit integer 28 number of columns
0016 unsigned byte ?? pixel
0017 unsigned byte ?? pixel
........
xxxx unsigned byte ?? pixel
Pixels are organized row-wise. Pixel values are 0 to 255. 0 means background (white), 255 means foreground (black).
$fh = fopen('train-images-idx3-ubyte', 'rb');
fseek( $fh, 16);
$byteString = fread($fh, 784);
$arr = unpack( 'C*', $byteString);
$arr[28] // яркость первого пикселя во второй строке
написать и подключить скриптGoogle Apps Script хорошо документрирован. У вас всё получится.
function nearest(arr, total) {
var len = arr.length
, i
, bit
, sum
, n = Math.pow(2, len)
, currDist
, index = undefined
, dist = undefined
, result = []
;
for( i = 1; i < n; i++) {
sum = 0;
for( bit = 0; bit < len; bit++) {
if( i & (1 << bit)) sum += arr[bit];
}
currDist = Math.abs(total - sum);
if( typeof dist === 'undefined' || dist > currDist) {
index = i;
dist = currDist;
if( dist === 0) break;
}
}
for(bit = 0; bit < len; bit++) {
if( index & (1 << bit)) result.push(arr[bit]);
}
return result;
}
nearest([1,3,4,6,8], 12) // [1,3,8]
nearest([1,2,4,6,8], 12) // [2,4,6]
nearest([7,9,13,19,28], 12) // [13] dist = 1
nearest([7,9,13,19,28], 28) // [9,19] не [28] т.к. останавливается на первом найденном варианте
0000 0010
│ │││┕╼ бит 0, чекбокс 0
│ ││└── бит 1, чекбокс 1
│ │└─── бит 2, чекбокс 2
│ └──── бит 3, чекбокс 3
└────── бит 4, чекбокс 4
switch( bitmap) {
case 0: // все выключены
// загрузить что-то там
break;
case 1<<3: // включен только 3-й бит
// загрузить что-то для 3-го чекбокса
break;
case 28: // вкл. 3, 4 и 5-й
// ...
}
Linux is a Unix clone written from scratch by Linus Torvalds with assistance from a loosely-knit team of hackers across the Net. It aims towards POSIX compliance.
Если функция сравнения compareFunction предоставлена, элементы массива сортируются в соответствии с её возвращаемым значением. Если сравниваются два элемента a и b, то:
Если compareFunction(a, b) меньше 0, сортировка поставит a по меньшему индексу, чем b, то есть, a идёт первым.
Если compareFunction(a, b) вернёт 0, сортировка оставит a и b неизменными по отношению друг к другу, но отсортирует их по отношению ко всем другим элементам. Обратите внимание: стандарт ECMAscript не гарантирует данное поведение, и ему следуют не все браузеры (например, версии Mozilla по крайней мере, до 2003 года).
Если compareFunction(a, b) больше 0, сортировка поставит b по меньшему индексу, чем a.
Функция compareFunction(a, b) должна всегда возвращать одинаковое значение для определённой пары элементов a и b. Если будут возвращаться непоследовательные результаты, порядок сортировки будет не определён.
id
находить весь элемент, данные в начале преобразовываются в «словарь» – объект, где свойства это id, а значения элементы.var data = [
{id: 0, name: 'Main', path: '/', childs: [1,2]},
{id: 1, name: 'One', path: '/one', childs: [3]},
{id: 2, name: 'Two', path: '/two', childs: []},
{id: 3, name: 'Three', path: '/one/three', childs: []}
];
function makeTree(d) {
var id, el, i, dict = {}, minId, r;
function parseChildren(el) {
var i, newEl;
for( i = 0; i < el.childs.length; i++) {
newEl = makeElement(dict[ el.childs[i] ]);
parseChildren( newEl);
el.children.push( newEl);
}
delete el.childs;
}
for( i = 0; i < d.length; i++) {
el = d[i];
id = el.id;
if( typeof minId === 'undefined' || minId > id) minId = id;
dict[id] = el;
}
r = makeElement( dict[minId] ); // root element
parseChildren(r);
return r;
}
function makeElement(arrElement) {
return {
name: arrElement.name,
path: arrElement.path,
childs: arrElement.childs,
children: []
};
}
var tree = makeTree(data);
/* {
"name": "Main",
"path": "/",
"children": [{
"name": "One",
"path": "/one",
"children": [{
"name": "Three",
"path": "/one/three",
"children": []
}]
}, {
"name": "Two",
"path": "/two",
"children": []
}]
} */
function stringInc(s) {
var pos = s.length - 1;
while(pos >= 0) {
if( Math.abs(s.charCodeAt(pos) - 52.5) < 5) pos--;
else break;
}
if( ++pos >= s.length) return s; // no number
var numLength = s.length - pos;
var numString = (parseInt(s.substr(pos)) + 1).toString();
if( numString.length < numLength) {
numString = ((Array(1 + numLength).join('0')) + numString).substr(-numLength);
}
return s.substr(0,pos) + numString;
}
stringInc('abc123') // abc124
stringInc('abc999') // abc1000
stringInc('abc00009') // abc00010
stringInc('009') // 010
stringInc('9') // 10
stringInc('aaa') // aaa
var result = { "areas": "значение для areas"}
peremennaya = {...тут весь этот JSON...}
peremennaya.mh // тут нужный массив
'' + el.title + ' - ' + el.count
var d = {"mh": [{"id": "BR", "count": 18516, "title": "Brazil"},
{"id": "US", "count": 4514, "title": "United States"},
{"id": "MY", "count": 390, "title": "Malaysia"},
{"id": "IT", "count": 208, "title": "Italy"}]
};
var result = {areas: d.mh.map(el => ({id:el.id, title:''+el.title+' - '+el.count}))}
// {"areas":[{"id":"BR","title":"Brazil - 18516"},{"id":"US","title":"United States - 4514"},
// {"id":"MY","title":"Malaysia - 390"},{"id":"IT","title":"Italy - 208"}]}
try_files $uri $uri/ /index.php?q=$uri&$args;
$_SERVER['REQUEST_URI']
и напишите просто try_files $uri $uri/ /index.php;
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [QSA,L]
"длина": [слово,слово]
words = txt.replace(/[\.,\?\!\:;\–\(\)]/g, '').toLowerCase().split(/\s+/);
// make dictionary
var db = [];
for( var i = 0; i < words.length; i++) {
word = words[i];
len = word.length;
if(db.length <= len || typeof db[len] == 'undefined') db[len] = [];
if(!~db[len].indexOf(word)) db[len].push(word);
}
function getWords(db, length, n) {
n = n || 3;
var result = [], offset = 0, m;
length = Math.max(0, Math.min(length, db.length));
while( result.length < n) {
m = n - result.length;
if( db[length + offset]) {
result = result.concat( getUpTo(m, db[length + offset]))
}
m = n - result.length;
if( offset && m && db[length - offset]) {
result = result.concat( getUpTo(m, db[length - offset]))
}
m = n - result.length;
if( m === 0) break;
offset++;
if( offset + length > db.length && offset > length) break;
}
return result;
}
function getUpTo(n, arr) {
return arr.slice(0, Math.min(n, arr.length));
}