Map [1]
| Operation | Time Complexity |
|---|---|
| Access | O(log n) |
| Search | O(log n) |
| Insertion | O(n) for <= 32 elements, O(log n) for > 32 elements [2] |
| Deletion | O(n) for <= 32 elements, O(log n) for > 32 elements |
| #!/bin/bash | |
| PID_FILE=~/.restic_backup.pid | |
| TIMESTAMP_FILE=~/.restic_backup_timestamp | |
| if [ -f "$PID_FILE" ]; then | |
| if ps -p $(cat $PID_FILE) > /dev/null; then | |
| echo $(date +"%Y-%m-%d %T") "File $PID_FILE exist. Probably backup is already in progress." | |
| exit 1 | |
| else |
| # Preloading usually required an extra query. | |
| # To do it in one query, a `join` is needed, and the call to `preload` needs to know the name of join | |
| # This macro does both the `join` and `preload` together | |
| defmodule Preloader do | |
| import Ecto, only: [assoc: 2] | |
| alias Ecto.Query.Builder.{Join, Preload} | |
| defmacro preload_join(query, association) do | |
| expr = quote do: assoc(l, unquote(association)) | |
| binding = quote do: [l] |
When setting these options consider the following:
sudo grep max_children /var/log/php?.?-fpm.log.1 /var/log/php?.?-fpm.log| defmodule MyApp.Scheduler do | |
| @moduledoc """ | |
| Schedules a Mix task to be run at a given interval in milliseconds. | |
| ## Options | |
| - `:task`: The name of the Mix task to run. | |
| - `:args`: A list of arguments to pass to the Mix task's `run/1` function. | |
| - `:interval`: The time interval in millisconds to rerun the task. |
When developing a program in Ruby, you may sometimes encounter a memory leak. For a while now, Ruby has a facility to gather information about what objects are laying around: ObjectSpace.
There are several approaches one can take to debug a leak. This discusses a time-based approach, where a full memory dump is generated every, say, 5 minutes, during a time that the memory leak is showing up. Afterwards, one can look at all the objects, and find out which ones are staying around, causing the
| #!/usr/bin/env bash | |
| # fresh-chrome | |
| # | |
| # Use this script on OS X to launch a new instance of Google Chrome | |
| # with its own empty cache, cookies, and user configuration. | |
| # | |
| # The first time you run this script, it will launch a new Google | |
| # Chrome instance with a permanent user-data directory, which you can | |
| # customize below. Perform any initial setup you want to keep on every |
| defmodule Expng do | |
| defstruct [:width, :height, :bit_depth, :color_type, :compression, :filter, :interlace, :chunks] | |
| def png_parse(<< | |
| 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, | |
| _length :: size(32), | |
| "IHDR", | |
| width :: size(32), | |
| height :: size(32), |
| # This is a skeleton for testing models including examples of validations, callbacks, | |
| # scopes, instance & class methods, associations, and more. | |
| # Pick and choose what you want, as all models don't NEED to be tested at this depth. | |
| # | |
| # I'm always eager to hear new tips & suggestions as I'm still new to testing, | |
| # so if you have any, please share! | |
| # | |
| # This skeleton also assumes you're using the following gems: | |
| # | |
| # rspec-rails: https://github.com/rspec/rspec-rails |