Skip to main content

Questions tagged [mixins]

A mixin is a way to enhance an object with properties or methods from another object.

Filter by
Sorted by
Tagged with
2 votes
0 answers
144 views

Type-safe mixin builder

The purpose of this code is to provide a type-safe approach to apply mixins to classes. It also prevents duplicate mixins. The code depends on ts-toolbelt. It is divided into multiple files, but I've ...
1 vote
2 answers
3k views

Ensuring that attributes referenced by a mixin are present in the children class

I have implemented the below _get_schema method to ensure that schema attribute is always present on the ...
32 votes
5 answers
5k views

Chess game for my students

I teach programming, and I currently teach my class about inheritance, abstract classes, and mixins. I wrote this code as an example, and I want to be sure it is as good as possible before I release ...
1 vote
1 answer
120 views

Applying a set of styles both with a media query and with nested rules

I am working on an application which responds to different screen resolutions. At a certain minimum DPI, we want to apply a set of styles. We also want to apply that same set of styles if the class <...
2 votes
2 answers
893 views

SASS mixin for a font-awesome before/after usage

In my SASS I use font-awesome declarations all over the place. I'm in love with it. I've created a SASS mixin for the usage: I started with the following: ...
1 vote
1 answer
53 views

Proper naming for objects which have a position and bounds on a plane

I have an interface which is for an object which has bounds in a 2D plane. ...
3 votes
0 answers
147 views

Boilerplate-free mixin pattern for a TypeScript charting library

The TypeScript handbook provides a mixin pattern but it requires a bunch of boilerplate, doesn't work for getters/setters and doesn't support defining default values (or any constructor work) in the ...
2 votes
1 answer
528 views

SASS/SCSS mixin for button states

I have created several mixins for a button to attempt to reduce duplication and contribute to the overall improvement of performance. I am looking for guidance on how to tighten this up so it is as ...
2 votes
1 answer
364 views

Less CSS Mixin for positioning with options for corresponding top, left, right, bottom values

I've created a Mixin in Less CSS. It can do the following things: Set the position-rule of an element. Place the element in one of the corners (e.g. top left, bottom right etc.) Alternatively it can ...
7 votes
1 answer
241 views

Create six hash tables - 2 hashing schemes x 3 collision handling schemes

I was asked to solve the following task: Given two methods for hashing (division and multiplication) and three methods for collision handling (chaining, open addressing w/ quadratic probing, ...
2 votes
1 answer
182 views

SASS mixin to define modifier classes for various screen sizes

I wish to make a mixin to produce the following result of modifier classes: ...
2 votes
0 answers
201 views

Copy-on-write in Ruby

I need to return private collection and avoid calling code modifying them avoiding copying overhead if possible So I thought of returning copy-on-write arrays, hashes, and sets. I couldn't find any ...
3 votes
1 answer
68 views

Implicit type class for updating maps

With the help of SO I got my code working, but I think it still could be improved, in particular I do not like using asInstanceOf. Is there some way how to avoid it?...
1 vote
1 answer
246 views

JavaScript inheritance with super calls and mixins

I needed JavaScript inheritance that offered calling of overridden methods (super calls). Furthermore I needed a possibiliy to add behaviour to instances (mixins). Mixins should not only be full ...
2 votes
0 answers
82 views

ActiveAdmin menu-generating mixin

I've written an ActiveAdmin mixin, such that you can include it and call simple_menu_for Foo, to reduce duplicate code when working with simple models. Here is the ...
2 votes
0 answers
202 views

Mixin implementation helper

While implementing things like repositories we often can see that reading and writing parts can be done totally independently. The same time client side will win from the single reference (who wants ...
8 votes
1 answer
449 views

A Mixin Comparator class

Idea: In C++, often a straightforward implementation of comparison operators is needed. In C++11, they can be conveniently implemented using std::tie. The following ...
4 votes
0 answers
91 views

Creating companion classes that are `inherited` onto any sub-classes

The idea for the code I have written came about due to the acts_as_versioned gem which automatically nests a Version class onto ...
4 votes
2 answers
106 views

Simple Translation Gem

I have a small gem that I've been maintaining. This gem provides a simple way to do translation using an alternative Google API. I've been working with Java last year and recently did some ...
2 votes
0 answers
271 views

Blade (similar to Jade) template with SCSS

I have this blade template with a main.scss file: ...
2 votes
0 answers
137 views

Modification of the headline line-height in the Compass vertical rhythm module

One thing nagged me about the compass vertical rhythm module; in the case the headline is too long and it occupies more than one line the line-height between the two lines looks way too massive and ...
2 votes
2 answers
333 views

Simulating MixIns with Java

I am using the following technique for simulating mixins (or Traits) using Java and would like to know whether this is reasonable or just confusing to future developers. Also, I believe a good naming ...
3 votes
0 answers
129 views

Extracting dynamic behaviors of state machines to modules

This is my initial class. (I am not trying to reinvent state-flows again, just practicing) As you can see straight forward, it dynamically generates methods like .recommend,.recommend!, ....
4 votes
1 answer
620 views

More elegant Sass @mixin to create pseudo-element shapes

I picked up Sass last week, and I'm already diving into expressions. I have a @mixin that creates a CSS border triangle using the following call: ...
10 votes
1 answer
411 views

Mixin and template-heavy code for a Silverlight clone

I've made a mock version of Silverlight in D2. It is meant to output HTML, but since I don't know HTML yet, its current output is in. HTML is not the reason I'm here, though. The goal of my project ...
5 votes
1 answer
4k views

Multiple inheritance Mixin class

I've written a simple class that somewhat simulates multiple inheritance using mixins. It allows you to extend the functionality of multiple classes and manage any conflicts between them, should they ...
4 votes
1 answer
220 views

Utility library and Underscore mixin - 1

This code is similar to Underscore. I've added in some functions to fill in different use cases. For example, one can use someKey to iterate through ...
9 votes
2 answers
5k views

Policy-based, variadic logger class in C++

I've been exploring design based around some of the more advanced C++11 features lately, and some of them are turning out to be rather useful for some projects I'm working on. One is this policy-based,...
3 votes
1 answer
111 views

JavaScript mixins, extending and super methods

I've read a lot of stuff about mixins, inheritance and such, and in the end I came up with this solution for extending a class with multiple mixins. I haven't seen this anywhere else... Is this a ...
0 votes
1 answer
645 views

JavaScript mixins - extending and super methods [closed]

I've read a lot of stuff about mixins, inheritance and such, and in the end I came up with this solution for extending a class with multiple mixins. I haven't seen this anywhere else... ...