Explore Public Snippets
Found 5,941 snippets matching: collection
public by shebin512 937155 3 6 0
Product Listing in Magento using SKUs
<html> <body> <?php /** * Code to fetch Products in collection and useing SKU's and display the products * */ $pCollection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToFilter( 'sku', array('in' => array( 18811601,51361203,51360601,18811602,51361201,83545603,18811603// Test Sku's //18807601,18807603,10264601,18792202, 83527701, 56821204// sku dev setup ) ) ) ->addAttributeToSelect('price') ->addAttributeToSelect('name') ->addAttributeToSelect('image') ->addAttributeToSelect('special_price'); //Media model to fetch Image URL $productMediaConfig = Mage::getModel('catalog/product_media_config'); ?> <div class="product-list owlCarousel"> <?php if (count($pCollectionBolt)>0){ foreach ( $pCollectionBolt as $_product) { //Mage::Helper('training')->getProductDetails($_product); You can use helper to display the product details as you Wish //I'm adding code here itself $_pSku = $_product->getSku(); $_pName = $_product->getName(); $_pUrl = $_product->getProductUrl(); $_pImageUrl = Mage::helper('catalog/image')->init($_product, 'image'); //$_pPrice = $_product->getPrice(); $_pPrice = $_product->getFinalPrice(); echo "<div><a href='".$_pUrl."'><img src='".$_pImageUrl."' alt='".$_pName."' /></a> <div class='productname-price'><a href='".$_pUrl."' style='min-height:0px;'>".$_pName."</a><span>₹".$_pPrice."</span></div> </div>"; } }else{ echo "<span style='text-align:center'>No products in the List</span>"; } ?> </div> </body> </html>
public by cghersi 475215 5 7 0
C#: Parse a comma separated string into a collection of numeric items
public static List<long> ParseIntoListOfLongs(string content, char separator = ',') { List<long> ids = new List<long>(); if (string.IsNullOrEmpty(content)) return ids; string[] strIds = content.Split(separator); foreach (string str in strIds) { long id = -1; if (long.TryParse(str, out id)) { if (id > 0) ids.Add(id); } } return ids; }
public by Geometry 112774 0 6 0
DeepClone: Copies a collection by calling the ICloneable.Clone method for each element inside it.
/// <summary> /// Copies a collection by calling the ICloneable.Clone method for each element inside it. /// </summary> /// /// <typeparam name="T"></typeparam> /// <param name="list">The collection to be cloned.</param> /// /// <returns>A copy of the collection where each element has also been copied.</returns> /// public static T DeepClone<T>(this T list) where T : IList<ICloneable>, ICloneable { T clone = (T)list.Clone(); for (int i = 0; i < clone.Count; i++) clone[i] = (ICloneable)list[i].Clone(); return clone; }
public by micurs 7684 4 9 11
Typescript + underscore: iterating through a collection property of a class
///<reference path='../types/node.d.ts'/> ///<reference path='../types/underscore.d.ts'/> import _ = require("underscore"); function write(msg) { process.stdout.write(msg+'\n'); } // Index Interface to locate a student given an id interface Students { [ studentId: number ] : Student; } class Student { private _id : number; private _name : string; private _lastName : string; constructor ( id: number, name : string, lastName : string ) { this._id = id; this._name = name; this._lastName = lastName; } // Property getters for Student get id() :number { return this._id; } get lastName() : string { return this._lastName; } } class Course { private title : string; _participants : Students = {}; constructor( t : string ) { this.title = t; } addStudent( s: Student ) { this._participants[s.id] = s; } getStudent( sid: number ) : Student { return this._participants[sid]; } // Property getter to retrieve the participants of a Course get participants() { return _.values(this._participants) } } var c = new Course("Computer Science 101"); c.addStudent(new Student(23,"Mark","Twain")); c.addStudent(new Student(100,"Albert","Einstein")); c.addStudent(new Student(120,"Isaac","Asimov")); _.each( c.participants , (s : Student) => write(s.lastName));
public by sTiLL-iLL @ SniPitz-KND 3599 4 8 25
Enumerator.js... behind every enumeration you'll find a good Iterator. I guess.... LoL
// slick as snot Enumerable type!!!! yeah! var Enum = { create: function (collection) { var index=0; return { next: function() { if (index < collection.length) { return ({ value: collection[index++], done: false }); } else { return ({ value: null, done: true}); } } }; } }; // use it like this... (strings, bool, numbers, all gewd!) var arr=['rtJKvE', '!!@wrh', 433, 'yippe', 216,'PRdUrg', 3038, 'whaa?'], it = Enumerator.create(arr), primer = 0; while(primer !== null) { primer = it.next().value; document.writeLine(primer); }
public by sTiLL-iLL @ SniPitz-KND 2908 7 8 21
... it's KliKQ.js & its meh family brah......
var KliKQ = (function () { function KliKQ() { this.mehArry = []; this.dahMap = {}; this.length = 0; } KliKQ.prototype.keyRoster = function () { var kz = []; this.eachIn(function (val, k) { kz.push(k); }); return kz; }; KliKQ.prototype.keyAssign = function (k, obj) { if (obj === 'undefined') { this.keyRemove(k); } else if (!this.dahMap.hasOwnProperty(k)) { this.dahMap[k] = this.mehArry.length; this.mehArry.push({ value: obj, key: k }); this.length++; } else { this.mehArry[this.dahMap[k]].value = obj; } }; KliKQ.prototype.keyPull = function (k) { if (this.dahMap.hasOwnProperty(k)) { return this.mehArry[this.dahMap[k]].value; } return undefined; }; KliKQ.prototype.idxGet = function (idx) { if (this.length <= idx) { return undefined; } return this.mehArry[idx].value; }; KliKQ.prototype.keyRemove = function (k) { if (this.dahMap.hasOwnProperty(k)) { var idx = this.dahMap[k], nam = ""; delete this.dahMap[k]; for (nam in this.dahMap) { if (this.dahMap.hasOwnProperty(nam) && this.dahMap[nam] >= idx) { this.dahMap[nam]--; } } this.mehArry.splice(idx, 1); this.length--; } }; KliKQ.prototype.eachIn = function (cback, slf) { var i = 0, ary = this.mehArry, len = ary.length; if (!slf) { slf = this; } while (i < len) { if (ary[i].value !== 'undefined') { cback.call(slf, ary[i].value, i, ary[i].key, this); } i++; } }; function kmprItems(dis, dat) { return (dis == dat) ? 0 : (dis < dat) ? -1 : 1; }; KliKQ.prototype.keySort = function (xprsn) { var i = 0, ary = this.mehArry, len = ary.length; if (!xprsn) { xprsn = kmprItems; } this.mehArry.sort(function (dis, dat) { return xprsn(dis.key, dat.key); }); while (i < len) { this.dahMap[ary[i].key] = i; i++; } }; return KliKQ; }());
public by sTiLL-iLL @ SniPitz-KND 2643 3 8 20
Linkage that works
'use strict'; function LinkedList(stringify, compare, iterable) { this.length = 0; this.head = new Item(true, this); this.tail = new Item(false, this); this.head.next = this.tail; this.tail.prev = this.head; this.sideTable = {}; if (typeof stringify === 'function') { this.stringify = stringify; } else if (Array.isArray(stringify)) { iterable = stringify; } if (typeof compare === 'function') { this.compare = compare; } else if (Array.isArray(compare)) { iterable = compare; } if (Array.isArray(iterable)) { iterable.forEach(function (item) { this.push(item); }, this); } } var lp = LinkedList.prototype; lp.push = function (value) { return this.tail.insertBefore(value); }; lp.pop = function () { if (this.tail.prev === this.head) { return undefined; } return this.tail.prev.destroy(); }; lp.unshift = function (value) { return this.head.insertAfter(value); }; lp.shift = function () { if (this.head.next === this.tail) { return undefined; } return this.head.next.destroy(); }; lp.clear = function () { this.head.next = this.tail; this.tail.prev = this.head; this.length = 0; this.sideTable = {}; }; lp.stringify = function (item) { if (typeof item === 'string') { return item; } }; lp.compare = function (a, b) { return a === b; }; lp.find = function (item) { if (!this.length) { return; } var key = this.stringify(item); if (typeof key === 'string') { if (key in this.sideTable) { return this.sideTable[key]; } return; } var cur = this.head.next; while (cur.next) { if (this.compare(item, cur)) { return cur; } else { cur = cur.next; } } }; lp.insert = function (item) { var current = this.find(item); if (current) { current.value = item; return current; } return this.push(item); }; lp.cache = function (item) { var key = this.stringify(item.value); if (typeof key === 'string') { this.sideTable[key] = item; return true; } return false; }; lp.decache = function (item) { var key = this.stringify(item.value); if (typeof key === 'string' && key in this.sideTable) { delete this.sideTable[key]; return true; } return false; }; function Item(list, value, prev, next){ if (list === false) { this.list = value; this.next = false; this.tail = true; return; } else if (list === true) { this.list = value; this.prev = false; this.head = true; return; } this.value = value; this.prev = prev; this.prev.next = this; this.next = next; this.next.prev = this; this.list = list; this.list.cache(this); } var ip = Item.prototype; ip.destroy = function () { if (this.list.length === 1) { this.list.clear(); return this.value; } this.list.decache(this); this.prev.next = this.next; this.next.prev = this.prev; this.list.length--; return this.value; }; ip.insertBefore = function (value) { if (this.head) { throw new Error('can\'t insert before the begining'); } this.list.length++; return new Item(this.list, value, this.prev, this); }; ip.insertAfter = function (value) { if (this.tail) { throw new Error('can\'t insert after the end'); } this.list.length++; return new Item(this.list, value, this, this.next); };
// dictionary structure function Diktionary(startValues) { this.values = startValues || {}; } Diktionary.prototype.store = function(name, value) { this.values[name] = value; }; Diktionary.prototype.lookup = function(name) { return this.values[name]; }; Diktionary.prototype.contains = function(name) { return (Object.prototype.hasOwnProperty.call(this.values, name) && Object.prototype.propertyIsEnumerable.call(this.values, name)); }; Diktionary.prototype.each = function(action) { forEachIn(this.values, action); }; function forEachIn(object, action) { try { for (var property in object) { if (Object.prototype.hasOwnProperty.call(object, property)) { action(property, object[property]); } } } catch (e) { if (e != Break) { throw e; } } }
public by cghersi 3295 1 8 1
LINQ: How to retrieve an IEnumerable collection with simple query
ICollection<User> users = new List<User>(); users.Add(new User("Tom")); users.Add(new User("Mark")); IEnumerable<User> result = ( from user in users where user.Active == true select user);
public by Geometry 1255 0 6 0
FindQuadrilateralCorners: Find corners of quadrilateral or triangular area, which contains the specified collection of points.
private static float quadrilateralRelativeDistortionLimit = 0.1f; /// <summary> /// Find corners of quadrilateral or triangular area, which contains the specified collection of points. /// </summary> /// /// <param name="cloud">Collection of points to search quadrilateral for.</param> /// /// <returns>Returns a list of 3 or 4 points, which are corners of the quadrilateral or /// triangular area filled by specified collection of point. The first point in the list /// is the point with lowest X coordinate (and with lowest Y if there are several points /// with the same X value). The corners are provided in counter clockwise order /// (<a href="http://en.wikipedia.org/wiki/Cartesian_coordinate_system">Cartesian /// coordinate system</a>).</returns> /// /// <remarks><para>The method makes an assumption that the specified collection of points /// form some sort of quadrilateral/triangular area. With this assumption it tries to find corners /// of the area.</para> /// /// <para><note>The method does not search for <b>bounding</b> quadrilateral/triangular area, /// where all specified points are <b>inside</b> of the found quadrilateral/triangle. Some of the /// specified points potentially may be outside of the found quadrilateral/triangle, since the /// method takes corners only from the specified collection of points, but does not calculate such /// to form true bounding quadrilateral/triangle.</note></para> /// /// <para>See <see cref="QuadrilateralRelativeDistortionLimit"/> property for additional information.</para> /// </remarks> /// public static List<IntPoint> FindQuadrilateralCorners( IEnumerable<IntPoint> cloud ) { // quadrilateral's corners List<IntPoint> corners = new List<IntPoint>( ); // get bounding rectangle of the points list IntPoint minXY, maxXY; PointsCloud.GetBoundingRectangle( cloud, out minXY, out maxXY ); // get cloud's size IntPoint cloudSize = maxXY - minXY; // calculate center point IntPoint center = minXY + cloudSize / 2; // acceptable deviation limit float distortionLimit = quadrilateralRelativeDistortionLimit * ( cloudSize.X + cloudSize.Y ) / 2; // get the furthest point from (0,0) IntPoint point1 = PointsCloud.GetFurthestPoint( cloud, center ); // get the furthest point from the first point IntPoint point2 = PointsCloud.GetFurthestPoint( cloud, point1 ); corners.Add( point1 ); corners.Add( point2 ); // get two furthest points from line IntPoint point3, point4; float distance3, distance4; PointsCloud.GetFurthestPointsFromLine( cloud, point1, point2, out point3, out distance3, out point4, out distance4 ); // ideally points 1 and 2 form a diagonal of the // quadrilateral area, and points 3 and 4 form another diagonal // but if one of the points (3 or 4) is very close to the line // connecting points 1 and 2, then it is one the same line ... // which means corner was not found. // in this case we deal with a trapezoid or triangle, where // (1-2) line is one of it sides. // another interesting case is when both points (3) and (4) are // very close the (1-2) line. in this case we may have just a flat // quadrilateral. if ( ( ( distance3 >= distortionLimit ) && ( distance4 >= distortionLimit ) ) || ( ( distance3 < distortionLimit ) && ( distance3 != 0 ) && ( distance4 < distortionLimit ) && ( distance4 != 0 ) ) ) { // don't add one of the corners, if the point is already in the corners list // (this may happen when both #3 and #4 points are very close to the line // connecting #1 and #2) if ( !corners.Contains( point3 ) ) { corners.Add( point3 ); } if ( !corners.Contains( point4 ) ) { corners.Add( point4 ); } } else { // it seems that we deal with kind of trapezoid, // where point 1 and 2 are on the same edge IntPoint tempPoint = ( distance3 > distance4 ) ? point3 : point4; // try to find 3rd point PointsCloud.GetFurthestPointsFromLine( cloud, point1, tempPoint, out point3, out distance3, out point4, out distance4 ); bool thirdPointIsFound = false; if ( ( distance3 >= distortionLimit ) && ( distance4 >= distortionLimit ) ) { if ( point4.DistanceTo( point2 ) > point3.DistanceTo( point2 ) ) point3 = point4; thirdPointIsFound = true; } else { PointsCloud.GetFurthestPointsFromLine( cloud, point2, tempPoint, out point3, out distance3, out point4, out distance4 ); if ( ( distance3 >= distortionLimit ) && ( distance4 >= distortionLimit ) ) { if ( point4.DistanceTo( point1 ) > point3.DistanceTo( point1 ) ) point3 = point4; thirdPointIsFound = true; } } if ( !thirdPointIsFound ) { // failed to find 3rd edge point, which is away enough from the temp point. // this means that the clound looks more like triangle corners.Add( tempPoint ); } else { corners.Add( point3 ); // try to find 4th point float tempDistance; PointsCloud.GetFurthestPointsFromLine( cloud, point1, point3, out tempPoint, out tempDistance, out point4, out distance4 ); if ( ( distance4 >= distortionLimit ) && ( tempDistance >= distortionLimit ) ) { if ( tempPoint.DistanceTo( point2 ) > point4.DistanceTo( point2 ) ) point4 = tempPoint; } else { PointsCloud.GetFurthestPointsFromLine( cloud, point2, point3, out tempPoint, out tempDistance, out point4, out distance4 ); if ( ( tempPoint.DistanceTo( point1 ) > point4.DistanceTo( point1 ) ) && ( tempPoint != point2 ) && ( tempPoint != point3 ) ) { point4 = tempPoint; } } if ( ( point4 != point1 ) && ( point4 != point2 ) && ( point4 != point3 ) ) corners.Add( point4 ); } } // put the point with lowest X as the first for ( int i = 1, n = corners.Count; i < n; i++ ) { if ( ( corners[i].X < corners[0].X ) || ( ( corners[i].X == corners[0].X ) && ( corners[i].Y < corners[0].Y ) ) ) { IntPoint temp = corners[i]; corners[i] = corners[0]; corners[0] = temp; } } // sort other points in counter clockwise order float k1 = ( corners[1].X != corners[0].X ) ? ( (float) ( corners[1].Y - corners[0].Y ) / ( corners[1].X - corners[0].X ) ) : ( ( corners[1].Y > corners[0].Y ) ? float.PositiveInfinity : float.NegativeInfinity ); float k2 = ( corners[2].X != corners[0].X ) ? ( (float) ( corners[2].Y - corners[0].Y ) / ( corners[2].X - corners[0].X ) ) : ( ( corners[2].Y > corners[0].Y ) ? float.PositiveInfinity : float.NegativeInfinity ); if ( k2 < k1 ) { IntPoint temp = corners[1]; corners[1] = corners[2]; corners[2] = temp; float tk = k1; k1 = k2; k2 = tk; } if ( corners.Count == 4 ) { float k3 = ( corners[3].X != corners[0].X ) ? ( (float) ( corners[3].Y - corners[0].Y ) / ( corners[3].X - corners[0].X ) ) : ( ( corners[3].Y > corners[0].Y ) ? float.PositiveInfinity : float.NegativeInfinity ); if ( k3 < k1 ) { IntPoint temp = corners[1]; corners[1] = corners[3]; corners[3] = temp; float tk = k1; k1 = k3; k3 = tk; } if ( k3 < k2 ) { IntPoint temp = corners[2]; corners[2] = corners[3]; corners[3] = temp; float tk = k2; k2 = k3; k3 = tk; } } return corners; }