public static IEnumerable<IEnumerable<T>> Split<T>(
this IEnumerable<T> source,
int count)
{
return source
.Select((x, y) => new { Index = y, Value = x })
.GroupBy(x => x.Index / count)
.Select(x => x.Select(y => y.Value).ToList())
.ToList();
}
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string className, string windowTitle);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ShowWindow(IntPtr hWnd, ShowWindowEnum flags);
[DllImport("user32.dll")]
private static extern int SetForegroundWindow(IntPtr hwnd);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowPlacement(IntPtr hWnd, ref Windowplacement lpwndpl);
private enum ShowWindowEnum
{
Hide = 0,
ShowNormal = 1, ShowMinimized = 2, ShowMaximized = 3,
Maximize = 3, ShowNormalNoActivate = 4, Show = 5,
Minimize = 6, ShowMinNoActivate = 7, ShowNoActivate = 8,
Restore = 9, ShowDefault = 10, ForceMinimized = 11
};
private struct Windowplacement
{
public int length;
public int flags;
public int showCmd;
public System.Drawing.Point ptMinPosition;
public System.Drawing.Point ptMaxPosition;
public System.Drawing.Rectangle rcNormalPosition;
}
private void BringWindowToFront()
{
IntPtr wdwIntPtr = FindWindow(null, "Put_your_window_title_here");
//get the hWnd of the process
Windowplacement placement = new Windowplacement();
GetWindowPlacement(wdwIntPtr, ref placement);
// Check if window is minimized
if (placement.showCmd == 2)
{
//the window is hidden so we restore it
ShowWindow(wdwIntPtr, ShowWindowEnum.Restore);
}
//set user focus to the window
SetForegroundWindow(wdwIntPtr);
}
pip install selenium
// Создадим простой текстовый файл:
var data = 'Здесь текст для файла или положите в переменную Blob';
var file = new File([data], 'primer.txt', {type: 'text/plain'});
// Создаем коллекцию файлов:
var dt = new DataTransfer();
dt.items.add(file);
var file_list = dt.files;
console.log('Коллекция файлов создана:');
console.dir(file_list);
// Вставим созданную коллекцию в реальное поле:
document.querySelector('input[type="file"]').files = file_list;
<input type="file">
- что просто архиполезно для браузерных ботов.var array = [4, 4, 5, 4];
var num = 4;
for(var index=array.length-1; index>=0; index--){
if(array[index] === num){
array.splice(index, 1);
console.log(index + " - позиции - " + num + " удалено");
}
}
console.log(array + " — остальные числа");
function max(data, key = n => n) {
const getVal = key instanceof Function ? key : n => n[key];
return Array.prototype.reduce.call(data, (max, n) => {
const val = getVal(n);
return max[0] > val ? max : [ val, n ];
}, [ -Infinity, undefined ])[1];
}
const { text } = max(arr, n => n.text.length);
const oldest = max(arr, 'age');