Earlier this week a co-worker of mine was working on some old code for running reports that had been written by someone who had long since departed. Every time he ran a report of a certain type he would always get wildly incorrect results. He had isolated the problem to a call to one particular method. RubyMine, his editor of choice, wasn't being very helpful in revealing the definition of the method. Exasperated, he said something to the effect of "How am I supposed to know where this method is defined?" I was more than a bit excited that I was able to tell him I knew of a way: Method#source_location
.
Method#source_location
returns the file name and line number where a given method is defined or nil if it's a native compiled method (e.g. part of the standard library). In order to actually use Method#source_location
one must first actually have a method. Fortunately this is pretty easy; the Object#method
method will return a Method
object when called on an instance. If all that is available is a Class
or Module
then Module#instance_method
can be used to get an UnboundMethod
object. Either will work.
Here is an example of Method#source_location
when called on a method that is defined in native code as part of the standard library.
2.4.1 :001 > x = 100 => 100 2.4.1 :002 > x.method(:to_s) => #<Method: Integer#to_s> 2.4.1 :003 > x.method(:to_s).source_location => nil
In an irb session a method's source location won't have a file name, but the result won't be nil.
2.4.1 :004 > class Hello 2.4.1 :005?> def hi 2.4.1 :006?> puts 'hi!' 2.4.1 :007?> end 2.4.1 :008?> end => :hi 2.4.1 :009 > Hello.new.method(:hi) => #<Method: Hello#hi> 2.4.1 :010 > Hello.new.method(:hi).source_location => ["(irb)", 5]
Here is an example of UnboundMethod#source_location
.
2.4.1 :011 > Hello.instance_method(:hi) => #<UnboundMethod: Hello#hi> 2.4.1 :012 > Hello.instance_method(:hi).source_location => ["(irb)", 5]
If given a file named "goodbye.rb" with the following contents...
class Goodbye def bye puts 'bye!' end end
...then here is an example of Method#source_location
for a method defined in a file.
2.4.1 :013 > require_relative 'goodbye' => true 2.4.1 :014 > Goodbye.new.method(:bye) => #<Method: Goodbye#bye> 2.4.1 :015 > Goodbye.new.method(:bye).source_location => ["/home/sean/goodbye.rb", 2]
And once again the UnboundMethod#source_location
version.
2.4.1 :016 > Goodbye.instance_method(:bye) => #<UnboundMethod: Goodbye#bye> 2.4.1 :017 > Goodbye.instance_method(:bye).source_location => ["/home/sean/goodbye.rb", 2]
Using this technique my co-worker was able to quickly identify where the method in question was defined. Case closed. Well, not quite. It turned out the method's source location raised more questions than it answered. The method he was looking for was in a related but different class from the one he was expecting. This seemed suspicious so I suggested he try inspecting the inheritance chain of the object the method was called on using Module#ancestors
method.
Module#ancestors
returned nothing out of the ordinary at first glance.
[ReportA, ReportBase, Object, ..., Kernel, BasicObject]
What was confusing though was that the source location for the method was inside ReportB
not ReportA
. So, just how was that happening? After staring at the ReportA
class for a minute I realized that it didn't inherit from ReportBase
, instead it included it. I had a hunch, so I suggested we take a look at the ReportBase
module.
Below is a minimal reproduction of the behavior.
module ReportBase def self.included(base) helpers = if base.const_defined?(:Helpers) base::Helpers.extend(Helpers) else Helpers end base.const_set(:Helpers, helpers) end module Helpers def greet puts 'greetings from ReportBase::Helpers#greet' end end end class ReportA include ReportBase module Helpers def greet puts 'greetings from ReportA::Helpers#greet' end end end class ReportB include ReportBase module Helpers def greet puts 'greetings from ReportB::Helpers#greet' end end end class ReportC include ReportBase end
ReportA
, ReportB
, and ReportC
are all pretty simple. All three include ReportBase
. ReportA
and ReportB
both have a submodule named Helpers
which defines a method named greet
.
Where things start to get a little strange is inside ReportBase
. The first thing to take note of is that Module#included
is overridden. Module#included
is a callback which is called whenever the module is included in another module or class. This allows for performing some specified action upon inclusion.
In the case of ReportBase
the callback first checks to see if the constant Helpers
is defined for the including class/module. If it is, then the including class/module's own Helpers
submodule is extended into the ReportBase::Helpers
submodule which is then assigned to helpers
otherwise ReportBase::Helpers
is assigned to helpers
. Then the including class/module's Helpers
constant is set to the helpers
.
The end result of this is that if the including class/module has its own Helpers
submodule then it is effectively merged with ReportBase::Helpers
which then overwrites the Helpers
submodule in the including class. This happens every time a class or module includes ReportBase
. Because Module#const_set
sets the Helpers
constant to the Module
object rather than creating a new copy this causes ReportBase::Helpers
to end up polluted with the Helpers
submodule of every class or module that include ReportBase
. Worse, it also pollutes the Helpers
submodule of each including class or module!
Below demonstrates the sort of frustration my co-worker was experiencing because of this.
2.4.1 :018 > require_relative 'report_test' => true 2.4.1 :019 > ReportA::Helpers.greet greetings from ReportB::Helpers#greet => nil 2.4.1 :020 > ReportB::Helpers.greet greetings from ReportB::Helpers#greet => nil 2.4.1 :021 > ReportC::Helpers.greet greetings from ReportB::Helpers#greet => nil
At the risk of being hyperbolic: this behavior is awful. Truly, maddeningly, awful. Please do not write code like this!
In retrospect, after careful dissection, this code makes perfect sense. However, at a glance, the actual behavior is surprising. If all I could look at was the definitions of ReportA
, ReportB
, and ReportC
it would take me ages to divine what is actually happening. And even with the source for ReportBase
it still wasn't obvious what the source of the behavior was until I spent several minutes parsing through it in my head and writing a minimal reproduction similar to the one presented here.
I think what the author of the code was trying to do was make it so helper methods from one report class were available in all report classes. That sounds like it might be useful, but the way it was done clobbers the namespacing that the actual structure of the code appears to have. Rails helpers actually have very similar behavior. I suspect that's where the idea for this reporting code was taken from.
This is definitely a case where the code was a little too magical. The most impactful change that could be made to the code would be to make inclusion of the helper modules be explicit. Rather than automatically extend all the helper modules into one module, each report class could instead explicitly include any helpers. The urge to be clever and creative when writing code for an unexciting task like generating reports can be great. You're better off resisting that urge and instead keep things explicit and unsurprising. Your co-workers and your future self will thank you for it.


{% extends "base.html" %} {% block content %}
Welcome to Ntersekt Chat, where the more you chat better we can match you with people like you.


We quickly see patterns and do automatic clustering without even thinking.
Most Basic Algorithm
Perfect result for k = 3
And this is the result for k = 10
Choose your favorite!
Density-Based Spatial Clustering
Original
Correlation
Reduced
notebook: pca_example
Rotate the camera to a position that reveals the most information
Visualizing High Dimensional Data
As humans looking at a computer screen we are naturally limited to two-dimensional visualizations that at best change over time and to reactions to interaction.
Searching for a low dimensional projection of the data that has the closest possible equivalent fuzzy topological structure (Riemannian manifold).
MNIST Digit Dataset
Fashion Items
A very short Introduction
Trained for two weeks on a single high-end GPU on CelebA-HQ data set (images of celebreties)
Visually-Aware Fashion Recommendation and Design with Generative Image Models
https://twitter.com/goodfellow_ian/status/918900712901197824


Disabling comments on all posts in wordpress
A few days before I started managing a wordpress blog with thousands of posts. The blog had been ignored for a few months and was full of spammy comments. The client asked me to disable comments on all posts for a few weeks. It is practically impossible to disable comments on thousands of posts by taking each individual post and unchecking allow comments checkbox. I figured my way around by executing an SQL query in the blog database to disable comments on all posts. Following are the steps to disable comments on all posts of a wordpress blog at once.
- Access the mysql database used by the blog using phpmyadmin or a similar tool
- Execute the following sql query
UPDATE wp_posts
SET comment_status = 'closed', ping_status = 'closed'
WHERE comment_status = 'open';
Please note that wp_ in wp_posts is the table prefix used in the database and it may vary according to the table prefix you chose during wordpress installation.


Classes
The following classes are available globally.
-
An empty dependencies container. It can be used for testing purposes or you don’t need dependencies
See moreDeclaration
Swift
public class EmptySideEffectDependencyContainer : SideEffectDependencyContainer
-
Helper Store type that is used as a partial type.
This type is very helpful when you want to pass the store to pieces of your application that must be aware of the type of state that the app manages but they should not care about the logic part (that is, the dependency container). A very common case is when you want to pass the store to the UI of your application. The UI shouldn’t access to the dependency container directly (it should dispatch a
SideEffect
instead) but you can still have type-safety over the state type that is managed.See moreWarning
you should not create this class directly. The class is meant to be used as a partial type erasure system overStore
-
The
Store
is a sort of single entry point that handles the logic of your application. In Katana, all the various pieces of information that your application manages should be stored in a single atom, called state (see alsoState
protocol).The
Store
, however, doesn’t really implements any application specific logic: this class only manages operations that are requested by the application-specific logic. In particular, you can require theStore
to execute something bydispatching a dispatchable item
.Currently the store handles 2 types of dispatchable:
State Updater
,Side Effect
Update the state
As written before, in Katana every relevant information in the application should be stored in the Store’s state. The only way to update the state is to dispatch a
StateUpdater
. At this point theStore
will execute the following operations:- it executes the interceptors
- it creates the new state, by invoking the
updateState
function of theStateUpdater
- it updates the state
- it resolves the promise
Handle to Business Logic
Non trivial applications require to interact with external services and/or implement complex logics. The proper way to handle these is by dispatching a
SideEffect
. TheStore
will execute the following operations:- it executes the interceptors
- it executes the
SideEffect
body - it resolves the promise
Listen for updates
You can attach a listener that is invoked every time the state changes by using
addListener
.Intercept Dispatchable
It is possible to intercept and reshape the behaviour of the
Store
by using aStoreInterceptor
. AStoreInterceptor
is executed every time something has dispatched, and before it is actually managed by theStore
. Here you implement behaviours like logging, blocking items before they’re executed and even change dynamically which dispatchable items arrive to theStore
itself.See also
StateUpdater
for more information about how to implement an update of the stateSee moreSee also
SideEffect
for more information about how to implement a complex/asynchronous logicDeclaration
Swift
open class Store<S, D> : PartialStore<S> where S : State, D : SideEffectDependencyContainer


Hi. This is the second part of my translation of the wonderful “Groupmates” section of the Namu Wiki article “Group Projects”. This one is going to talk about the Weird and the Normal types of groupmates which you would almost always encounter.
Esoteric but not necessarily bad
The Lazy Genius
The case when a person is waaay beyond competent but are very lazy.
These people usually do something else when others debate and work with the project. So people who don’t recognize a Lazy Genius might view him or her as freeloaders or plainly lazy people. Even when he/she is reporting he’s very lax and chill, so other members might question the attitude of this guy.
Of course, their abilities show through their results. Doesn’t show up to meetings, looks at the presentations on the day itself, presents based on background knowledge, gets A+. In debates, they just take a look at the topic and completely wrecks the other side, or solves a problem that three people worked on for 30 minutes with one suggestion.
For these people, their concept of “common knowledge” is different from the normal “common knowledge”. For other people, these things are really difficult things that needs to be researched for hours on the internet. But for these people, it’s “Do I necessarily have to research this?” so they find prep time for presentations a waste. When they don’t pay attention to meetings, they’re basically saying “LOL what an easy problem, what’s the matter with them…”
Since the results are good no one can really attack their lack of participation. He can just say “dude I carried and we got a good score right?” and no one can really say anything.
To use these people well, give them two peoples’ worth of work and give him an “assistant” who’s job it is to ‘do the dirty work’ and ‘to keep the Lazy Genius in check’. Then they can show great ability better than a well trained corporal in the military. Do not make lazy geniuses leaders because leaders have to take care of a lot of menial things but these people are lazy.
Members with Connections
These people know other people who are experts at their majors. This happens more often in Archi or Engineeringg courses or the Arts. These people can just ask for materials from their connections so people w/o connections would obviously be at a disadvantage. It feels very unfair when this type of member says “That’s all you can do?”, “You gotta try harder”, or “Can you please get out of our group?” just because you don’t have connections. Yeah, they got connections, but the question is do they have actual skill?. And it’s bearable if the member actually got good materials, but if he/she keeps trash-talking but the results are bad…
In law or business sometimes the prof asks you to interview lawyers or high-ranking officials from big companies. It’s like they’re testing your connections and not your ability. Even if you say that you don’t have connections, the prof would just cut with “Try harder, if you try hard enough you’d find one”. So the tasks ends with either paying a lawyer in the neighborhood or getting a bad grade. This happens because the prof’s standard of his friends makes him think that “You’d know at least one lawyer or officer in your life”. Of course, that’s not true for most other people. However, if your parents have connections then you can do these things well enough.
Normal members
Half-forced Solo-Carry
Unlike voluntary solo-carries, these people were forced to solo-carry a group project. Most people who complain about group works are in this type.
- If there’s a 5 member group project but two people withdrew the class. If it’s only the first few days of the work, you could move somewhere else; however, if it’s already halfway through you’re forced to carry on with lacking members.
- Due to circumstance or personality, other members quietly force the one person to solo-carry. Of course, the quality of the work would deteriorate in this case because the carry was forced to carry. Unfortunately, most professors don’t actually check participation in the groups, and peer reviewing will always end up with high scores for everyone (…) therefore it really sucks to be a half-forced Solo-carry.
The quiet member
This type of member aren’t very active, but they receive orders and do them well. Although there are quiet members who are actually good at their work, some of them are just hard-working without much ability(…). At least these types are better than freeloaders. But they have little to no impact in the group.
Most quiet members produce decent output unless very unlucky.
Me, Myself, and I
This type of members are similar to Solo-Carries but they never do more than their assigned work. They might be good at their work, but they refuse anyone who tries to give them more work. This is why they tend to be viewed as uncooperative, and even if they do well, if the rest of the members suck, the entire thing collapses. At least they’re not freeloaders.
But if everyone in a group is of this type, that group fails. No exceptions.
Everyone else is too good for me
This situation (not really a type) occurs when good and bad groupmates are obviously defined. Say there are two 4th year cum laude students and some normal 1st year students. The latter will never reach the standards of the former. These people are sometimes relegated to doing menial tasks but that might as well be the best choice because when this type of groupmate is given important work, either the work turns out to be bad or the person in question crumbles to pressure.


*CSET 160.4*: MOAR RAILS! How to use these slides: * P toggle presenter notes * ? help menu * → next slide Also, [here's the source](https://github.com/chadoh/cset160) --- CSET 160.4 # MOAR RAILS! --- attendance # a two-tiered list tasks **and sub-tasks**; *video games **and their characters**;* sports teams **and their players** --- class: small Lab # Build it Make a Rails app that allows listing a thing, and then also allows listing sub-things for each thing. Stuck? Keep working on [last lesson's lab](/sessions/3/#29)


Thanks for visiting our business hub - find out information about business here.
{{ cat }}
{% endfor %}Select a category to view the most frequently asked questions for that section
Feeling out of touch with clientele or customer base? You need this section.
Go to sectionImproving your marketing strategy? We have a great FAQ section for that
Go to sectionNot sure what technology your business needs? Find out more in this section
Go to sectionLooking for assistance with the finances? Click below to find the best
Go to sectionTake a look at the most recent knowledge articles here


fn:input() → node*
Function signature
|
Result |
node() * |
Removed in Saxon 7.8
Note: This implementation of the input() function is very simple. If the parameter {http://saxon.sf.net/}input has been supplied to the transformation, the function returns the value of this parameter. This must be a node sequence - which means it cannot be supplied from the command line. If no such parameter has been supplied, it returns the root of the principal source document (the document containing the node that was matched on entry to the transformation).


Please enable JavaScript and refresh this page
Created by: EPluribusNEOLecense: Apache Version 2.0 Get the source code: GitHub


How to make randomly distributed points less random and more evenly spread out.
With only random distribution the results can include overlapping points, clusters of points and a somewhat uneven distribution throughout the grid. If you needed a more even distribution you could check each new point against every other point to prevent overlaps or clustering. This has an exponential problem O(n2) and makes the algorithm unscalable and inefficient. The solution is the Poisson Disc Sampling Algorithm.
Here we can see a considerably more even, yet still random distribution of points. By using a background grid method each new point can easily check its immediate neighbours without having to worry about all the points on the grid. This makes the algorithm much faster and scalable and is now an O(2n) operation.
Draw random points with a minimum separation of (r)
Watch the algorithm solve the puzzle one step at a time. Red points are Active and will be visited again to check if another point can be inserted nearby. Once the algorithm has decided a point cannot have any more neighbours it changes to black and becomes a fixed, closed point on the grid. Once there are no more Active points the solution has been reached.
r - The minimum distance between points.
k - The number of attempts to create a new point before deciding the current point should be closed.
n - The number of dimensions the grid has. This algorithm can distribute points in 3d, 4d, 5d etc. I'll do another example for 3d.
cell size - The size of the grid cells is calculated by r / sqrt(n)
The algorithm takes as input the extent of the sample domain in Rn, the minimum distance r between samples, and a constant k as the limit of samples to choose before rejection in the algorithm (typically k = 30).
Step 0. Initialize an n-dimensional background grid for storing samples and accelerating spatial searches. We pick the cell size to be bounded by r/√n, so that each grid cell will contain at most one sample, and thus the grid can be implemented as a simple n-dimensional array of integers: the default −1 indicates no sample, a non-negative integer gives the index of the sample located in a cell.
Step 1. Select the initial sample, x0, randomly chosen uniformly from the domain. Insert it into the background grid, and initialize the “active list” (an array of sample indices) with this index (zero).
Step 2. While the active list is not empty, choose a random index from it (say i). Generate up to k points chosen uniformly from the spherical annulus between radius r and 2r around xi. For each point in turn, check if it is within distance r of existing samples (using the background grid to only test nearby samples). If a point is adequately far from existing samples, emit it as the next sample and add it to the active list. If after k attempts no such point is found, instead remove i from the active list
let width = 400;
let height = 400;
let r = 25;
let k = 30;
let n = 2;
let myPoisson = new PoissonDisc(width, height, r, k, n);
myPoisson.run();
Points are available in the myPoisson.points array. Point.px and Point.py are the x and y position.
Please visit GitHub to download the full source code. Released as public domain for anyone to use.
Fast Poisson Disc Sampling in Arbitrary Dimensions By Robert Bridson ~ University of British Columbia
Download the PDF
Thanks to all the internet people who posted the videos, articles and examples for me to learn from. Hopefully this example can add to that knowledge base for future coders. Inspired by The Coding Train poisson video.


Hi! I am a Data Scientist at Quantzig.
I graduated from PESIT, Bangalore in 2018 with a Bachelor's degree in Mechanical Engineering.
I'm also currently doing a Post Graduate program at IIIT, Bangalore for Data Science.
I like solving interesting problems and providing solutions by using data. You can find the link to some of my work below.
Development and testing of data product to convert raw financial data from multiple sources into actionable insights.
Obtained exposure to Image Recognition and Optical Character Recognition techniques using OpenCV and Tesseract engine.
Worked with the following tools: Python, Flask, Tesseract, MongoDB, Selenium, BeautifulSoup
Bachelor's degree in Mehcanical Engineering with specialization in Energy.
Windows. Linux. MySQLMongoDB
English. Hindi. Marathi
Music. Reading. Travel
Clean Tech
Bangalore, India
<EMAIL_ADDRESS>Phone:
+91<PHONE_NUMBER>