Adds a job of type <tt>klass<tt> to the queue with <tt>options<tt>. Returns the UUID of the job override to pass actual parameters instead of a single hash, to make backward compatible with existing resque jobs.
# File lib/resque_ui/overrides/resque_status/job_with_status.rb, line 9 def self.enqueue(klass, options = {}) uuid = Resque::Status.create :name => "#{self.name}: #{options.inspect}" Resque.enqueue(klass, uuid, options) uuid end
Create a new instance with uuid
and options
OVERRIDE to add the worker attr
# File lib/resque_ui/overrides/resque_status/job_with_status.rb, line 45 def initialize(uuid, worker = nil, options = {}) @uuid = uuid @options = options @worker = worker end
This is the method called by Resque::Worker when processing jobs. It creates a new instance of the job class and populates it with the uuid and options.
You should not override this method, rather the perform
instance method. OVERRIDE to pass the block in order to set the worker
status, returns the worker object
# File lib/resque_ui/overrides/resque_status/job_with_status.rb, line 57 def self.perform(uuid=nil, options = {}) uuid ||= Resque::Status.generate_uuid worker = yield if block_given? instance = new(uuid, worker, options) instance.safe_perform! { |status| yield status if block_given? } instance end
# File lib/resque_ui/overrides/resque_status/job_with_status.rb, line 99 def counter(counter) Resque::Status.counter(counter, uuid) end
# File lib/resque_ui/overrides/resque_status/job_with_status.rb, line 95 def incr_counter(counter) Resque::Status.incr_counter(counter, uuid) end
# File lib/resque_ui/overrides/resque_status/job_with_status.rb, line 91 def name "#{self.class.name}: #{options.inspect}" end
Pause the current job, setting the status to ‘paused’
# File lib/resque_ui/overrides/resque_status/job_with_status.rb, line 36 def pause! set_status({ 'status' => 'paused', 'message' => "#{worker} paused at #{Time.now}" }) end
Run by the Resque::Worker when processing this
job. It wraps the perform
method ensuring that the final
status of the job is set regardless of error. If an error occurs within the
job’s work, it will set the status as failed and re-raise the error.
# File lib/resque_ui/overrides/resque_status/job_with_status.rb, line 69 def safe_perform! unless should_kill? || (status && status.killed?) set_status({'status' => 'working'}) perform { |status| yield status if block_given? } kill! if should_kill? completed unless status && status.completed? on_success if respond_to?(:on_success) end rescue Killed logger.info "Job #{self} Killed at #{Time.now}" Resque::Status.killed(uuid) on_killed if respond_to?(:on_killed) rescue => e logger.error e failed("The task failed because of an error: #{e}") if respond_to?(:on_failure) on_failure(e) else raise e end end
sets the status of the job for the current iteration. You should use the
at
method if you have actual numbers to track the iteration
count. This will kill the job if it has been added to the kill list with
Resque::Status.kill()
# File lib/resque_ui/overrides/resque_status/job_with_status.rb, line 19 def tick(*messages) kill! if should_kill? || status.killed? set_status({'status' => 'working'}, *messages) # check to see if the worker doing the job has been paused, pause the job if so if self.worker && self.worker.paused? loop do # Set the status to paused. # May need to do this repeatedly because there could be workers in a chained job still doing work. pause! unless status.paused? break unless self.worker.paused? sleep 60 end set_status({'status' => 'working'}, *messages) unless status && (status.completed? || status.paused? || status.killed?) end end


Note
Click here to download the full example code
2.1.3. Extending py-fmas by optfrog spectrograms¶
This examples shows how to use the py-fmas library code in conjunction with the optFrog spectrogram tool.
In particular, the example details a numerical experiment performing pulse propagation in terms of the simplified forward model for the analytic signal including the Raman effect [1]. Here, the model is used to perform simulations on supercontinuum generation for an instance of a highly nonlinear photonic crystal fiber (PCF) with an anomalous group-velocity dispersion regime [2]. The example also includes data postprocessing by calculating an analytic signal spectrum with optimized time-frequency resolution using the optfrog-tool [3].
An example that shows how to use the simple py-fmas native spectrogram is shown under the link below:
- Note:
For this exampe to run, the optfrog tool needs to be installed [3].
The py-fmas package includes a simple spectrogram in module tools. The optfrog Python package however includes extended functionality by allowing a user to calculate spectrograms with optimized time and frequency resolution.
- References:
[1] A. Demircan, Sh. Amiranashvili, C. Bree, C. Mahnke, F. Mitschke, G. Steinmeyer, Rogue wave formation by accelerated solitons at an optical event horizon, Appl. Phys. B 115 (2014) 343, http://dx.doi.org/10.1007/s00340-013-5609-9
[2] J. M. Dudley, G. Genty, S. Coen, Supercontinuum generation in photonic crystal fiber, Rev. Mod. Phys. 78 (2006) 1135, http://dx.doi.org/10.1103/RevModPhys.78.1135
[3] O. Melchert, B. Roth, U. Morgner, A. Demircan, OptFROG — Analytic signal spectrograms with optimized time–frequency resolution, SoftwareX 10 (2019) 100275, https://doi.org/10.1016/j.softx.2019.100275, code repository: https://github.com/ElsevierSoftwareX/SOFTX_2019_130.
Out:
# optFrog convergence info:
# (sigma) (Q(sigma, alpha=0.000000)) (IAE1) (IAE2)
355.959086 0.570680 1.101932 0.039428
573.313374 0.616589 1.200919 0.032259
221.626749 0.531656 0.991327 0.071986
138.604799 0.507169 0.892059 0.122278
87.294411 0.488869 0.786706 0.191033
55.582848 0.466704 0.665983 0.267425
35.984024 0.447466 0.541951 0.352981
23.871285 0.437389 0.432716 0.442062
16.385200 0.445184 0.354833 0.535534
25.575392 0.438465 0.449987 0.426944
22.988308 0.437094 0.423509 0.450678
20.466145 0.438235 0.397714 0.478756
22.706287 0.437021 0.420520 0.453522
21.850629 0.437280 0.411743 0.462818
22.585945 0.437029 0.419271 0.454787
22.688130 0.437019 0.420330 0.453708
22.665447 0.437019 0.420096 0.453943
22.679466 0.437019 0.420241 0.453797
22.677702 0.437019 0.420223 0.453815
22.673021 0.437019 0.420174 0.453863
22.674907 0.437018 0.420194 0.453843
22.675229 0.437018 0.420197 0.453840
22.674560 0.437018 0.420190 0.453847
22.673972 0.437018 0.420184 0.453853
22.674336 0.437018 0.420188 0.453849
22.674510 0.437018 0.420190 0.453847
22.674467 0.437018 0.420189 0.453848
22.674417 0.437018 0.420189 0.453848
22.674443 0.437018 0.420189 0.453848
22.674439 0.437018 0.420189 0.453848
22.674431 0.437018 0.420189 0.453848
22.674436 0.437018 0.420189 0.453848
import fmas
import numpy as np
from fmas.models import CustomModelPCF
from fmas.solver import IFM_RK4IP
from fmas.analytic_signal import AS
from fmas.grid import Grid
from fmas.tools import plot_spectrogram
from optfrog import optFrog
def main():
# -- DEFINE SIMULATION PARAMETERS
# ... COMPUTATIONAL DOMAIN
t_max = 3500. # (fs)
t_num = 2**14 # (-)
z_max = 0.10*1e6 # (micron)
z_num = 8000 # (-)
z_skip = 10 # (-)
# ... INITIAL CONDITION
P0 = 1e4 # (W)
t0 = 28.4 # (fs)
w0 = 2.2559 # (rad/fs)
E_0t_fun = lambda t: np.real(np.sqrt(P0)/np.cosh(t/t0)*np.exp(-1j*w0*t))
# -- INITIALIZATION STAGE
grid = Grid( t_max = t_max, t_num = t_num, z_max = z_max, z_num = z_num)
model = CustomModelPCF(w=grid.w)
solver = IFM_RK4IP( model.Lw, model.Nw, user_action = model.claw)
solver.set_initial_condition( grid.w, AS(E_0t_fun(grid.t)).w_rep)
# -- RUN SIMULATION
solver.propagate( z_range = z_max, n_steps = z_num, n_skip = z_skip)
# -- POSTPRICESSING: COMPUTE SPECTROGRAM USING OPTFROG
# ... Z-DISTANCE, Z-INDEX AND FIELD FOR WHICH TO COMPUTE TRACE
z0 = 0.08e6 # (micron)
z0_idx = np.argmin(np.abs(solver.z-z0))
Et = solver.utz[z0_idx]
# ... WINDOW FUNCTION FOR SIGNAL LOCALIZATION
def window_fun(s0):
return lambda t: np.exp(-t**2/2/s0/s0)/np.sqrt(2.*np.pi)/s0
# ... OPTFROG TRACE
res = optFrog(
grid.t, # TEMPORAL GRID
Et, # ANALYTIC SIGNAL
window_fun, # WINDOW FUNCTION
tLim = (-500.0, 3200.0, 10), # (tmin, fs) (tmax, fs) (nskip)
wLim = (0.9, 4.1, 3) # (wmin, fs) (wmax, fs) (nskip)
)
# ... SHOW SPECTROGRAM
plot_spectrogram(res.tau, res.w, res.P)
if __name__=='__main__':
main()
Total running time of the script: ( 1 minutes 21.680 seconds)


Not all lenders are equal - The Mortgage Gal
by Tracy HeadLast week, a client asked why I chose a particular lender for them.
It was a great question, so I spent some time breaking down why we went the route we did.
When I work with clients, I look at their overall picture before deciding which lender to place their mortgage with.
Rate, although an important consideration, is not always the deciding factor. Each lender has slightly different guidelines, policies, and processes.
Each client’s situation is slightly different.
The type of property you are looking to purchase can rule out certain lenders. As an example, if you are looking to purchase an acreage or rural property, some lenders are more receptive to those applications.
Your financial situation may affect which route we go.
During the last few months, we’ve seen a few more lenders willing to consider Child Tax Credit income for qualifying purposes.
Among these lenders, there are some that will use 100% of the income, while others have caveats about this income being used, but only to a maximum percentage of overall family income.
Your time frame may direct us to one lender over another. There are a few we work with who can process an application from start to finish really quickly.
If you own one or more rental properties, the way that lenders calculate the rental income and expenses can make a significant difference in the amount you qualify to borrow.
Some lenders have a cap on the number of properties that their clients own, whereas others do not.
If you are writing an offer with a closing date way down the road, some lenders will only issue an approval if you are within ninety days of the closing date, while others will issue an approval up to 120 days out.
One of the most important things I look at is how the lender calculates any prepayment penalties. Some will use what they call their posted rate as opposed to their best rate, which can make a huge difference in the penalty levied if you pay your mortgage out early.
Finally, if clients are in the middle of a term with one lender and are looking to make a move, it's best to explore options with the current lender first.
I would far rather we try to save any penalty by porting their current mortgage, or if the closing dates don’t quite line up going back to the same lender for a replacement mortgage.
Just because one lender has said no does not necessarily mean you don’t have any options.
Sometimes trying to find the right product for clients feels a bit like working on a Rubik’s cube.
Getting all of the pieces to line up can be a bit of a puzzle, but mortgage clients today are fortunate to have access to many different lenders and many different options.


--- layout: post title: Javascript quiz. ES6 edition. tags: - js new: new ---
Remember that crazy Javascript quiz from 6 years ago? Craving to solve another set of mind-bending snippets no sensible developer would ever use in their code? Looking for a new installment of the most ridiculous Javascript interview questions?
Look no further! The "ECMAScript Two Thousand Fifteen" installment of good old Javascript Quiz is finally here.
The rules are as usual:
The quiz goes over such ES6 topics as: classes, computed properties, spread operator, generators, template strings, and shorthand properties. It's relatively easy, but still tricky. It tries to cover various ES6 features — a little bit of this, a little bit of that — but it's certainly still only a tiny subset.
If you can think of other silly riddle ideas to break one's head against, please post them in the comments. For a slightly harder version, feel free to explore some of the tests in our compat table or perhaps something from TC39 official test suite.
Ready? Here we go.
{% gist kangax/b4c7ec851cdeaa1d89cd %}
{% gist kangax/934a12f3e5f5d1f6a41b %}
{% gist kangax/8aba5d9488594e942e87 %}
{% gist kangax/8b37c698093d9ac196df %}
{% gist kangax/4d0deaad37316eccf6b3 %}
{% gist kangax/bb2dc76e683f5b239d78 %}
{% gist kangax/d86c9641a9e9e6d70025 %}
{% gist kangax/a72fad89b34f2918724e %}
{% gist kangax/483d85070c5deacfda80 %}
{% gist kangax/327b3da882d027893e88 %}
{% gist kangax/f0b8ae23e9cc858a0bde %}
{% gist kangax/4fa8a01567cebc7dbd7b %}
Here be quiz result
I hope you enjoyed it. I'll try to write up an explanation for these in the near future.
Vote on Hacker News Tweet