Skip to content

Instantly share code, notes, and snippets.

View AndrewBuntsev's full-sized avatar

Andrei Buntsev AndrewBuntsev

View GitHub Profile
var sortBy = function(arr, ...sortByArgs){
arr.sort(function(a,b){
var sortResult = 0;
sortByArgs.forEach(function(arg){
if (sortResult != 0) return;
if(Object.values(arg)[0] == 'desc'){
var propName = Object.keys(arg)[0];
if (a[propName] > b[propName]){
sortResult = -1;
return;
<DevicesConfiguration>
<devices>
<device type="SM_G920I###6.0.1">
<touchActivities>
<touchActivity type="ToggleFlightMode">
<points>
<point x="500" y="1800" id="1"/>
<point x="1300" y="430" id="2"/>
</points>
</touchActivity>
///
/// ConfigurationElement with additional Id property
///
public abstract class IdentifiableConfigurationElement : ConfigurationElement
{
public virtual string Id { get; }
}
///
/// Generic ConfigurationElementCollection
<configSections>
<section name="DevicesConfiguration" type="MyNamespace.DevicesConfigurationSection, MyNamespace" />
</configSections>
var devicesConfiguration = System.Configuration.ConfigurationManager
.GetSection("DevicesConfiguration") as DevicesConfigurationSection;
public class DevicesConfigurationSection : ConfigurationSection
{
[ConfigurationProperty("devices")]
[ConfigurationCollection(typeof(DeviceConfigElement), AddItemName = "device", CollectionType = ConfigurationElementCollectionType.BasicMap)]
public ConfigurationElementCollection<DeviceConfigElement> Devices => base["devices"] as ConfigurationElementCollection<DeviceConfigElement>;
}
public class DeviceConfigElement : IdentifiableConfigurationElement
{
public override string Id => Type;
const movies = [
{
"Title": "Inception",
"Year": "2010",
"Director": "Christopher Nolan"
},
{
"Title": "Interstellar",
"Year": "2014",
"Director": "Christopher Nolan"
Array.prototype.groupBy = function(field){
let groupedArr = [];
this.forEach(function(e){
//look for an existent group
let group = groupedArr.find(g => g['field'] === e[field]);
if (group == undefined){
//add new group if it doesn't exist
group = {field: e[field], groupList: []};
groupedArr.push(group);
}
<script src='https://unpkg.com/sweetalert2@7.17.0/dist/sweetalert2.all.js'></script>
<button id='swal-popup-example-button'>Click Me</button>