xml – How to generate map tiles using MapProxy & Openlayer?

I have created a map using openlayer 2,mapnik & Tilecache. Now I want to upgrade to openlayers latest version (3 or 5) & MapProxy 1.12. For that I have a sample.yaml ,which I run using command mapproxy-util serve-develop sample.yaml. But the tiles are not generating. I am getting error unknown layer: district.

sample.yaml

services:
  tms:
    use_grid_names: true
    # origin for /tiles service
            
layers:
  - name: district
    title: District Layer
    sources: (dist_cache)

caches:
  dist_cache:
    grids: (GLOBAL_GEODETIC) #(distgrid) 
    sources: (dist_tms)   
    base_dir: /var/www/mapproxycache 

sources:
  dist_tms:
    type: tile
    url: /path/to my xml file/district.xml
    grid: distgrid  
    
grids:
     distgrid:
         base: GLOBAL_GEODETIC

globals:

map.js (openlayer 2)

var layer = new OpenLayers.Layer.TMS('TMS district', 'http://localhost:8080/tiles/', {layername: 'district/distgrid', type: 'png', tileSize: new OpenLayers.Size(256, 256) });
map.addLayer(layer);

district.xml

<Map background-color="#fff" srs="+proj=utm +zone=43 +datum=WGS84 +units=m +no_defs" buffer-size="128" minimum-version="0.7.2">
<Style name="District_style_line">
<Rule>
<MaxScaleDenominator>6600000000</MaxScaleDenominator>
<PolygonSymbolizer fill="#ebb1af"/>
<LineSymbolizer stroke="rgb(0,0,0)" stroke-width="0.98" stroke-linejoin="round"/>
</Rule>
</Style>
<Style name="District_style_text">
<Rule>
<MaxScaleDenominator>6600000</MaxScaleDenominator>
<TextSymbolizer face-name="DejaVu Sans Bold" size="8" fill="black" wrap-width="10" avoid-edges="false" placement="interior">(name)</TextSymbolizer>
<MinScaleDenominator>2000000</MinScaleDenominator>
</Rule>
</Style>
<Layer name="District_Boundary" srs="+proj=utm +zone=43 +datum=WGS84 +units=m +no_defs">
<StyleName>District_style_line</StyleName>
<StyleName>District_style_text</StyleName>
<Datasource>
<Parameter name="dbname">sampledb</Parameter>
<Parameter name="extent">291627,904686,958569,1426831</Parameter>
<Parameter name="geometry_field">the_geom</Parameter>
<Parameter name="host">localhost</Parameter>
<Parameter name="password">password</Parameter>
<Parameter name="port">5432</Parameter>
<Parameter name="srid">32643</Parameter>
<Parameter name="table">select name,the_geom from district</Parameter>
<Parameter name="type">postgis</Parameter>
<Parameter name="user">user</Parameter>
</Datasource>
</Layer>
</Map>

beginner – App to seed DB, generate CSVs, and export individually or in complex zip files Rails 5

I have an app whose sole purpose is to seed data files and add the data to different CSVs which are zipped and exported by the user. My application controller is filled with lines that all look like this:

  def export_tips
    @appointments = Appointment.order('service_id')
    send_data @appointments.to_csv_tips, filename: 'tips.csv'
  end

  def export_ticketpayments
    @appointments = Appointment.order('service_id')
    send_data @appointments.to_csv_ticketpayments, filename: 'ticketspaymentitems.csv'
  end

  def export_batchmanifest
    @batchmanifests = Batchmanifest.all
    send_data @batchmanifests.to_csv_batchmanifest, filename: "batch_manifest-#{Date.today}.csv"
  end

  def export_pets
    @clients = Client.all
    send_data @clients.to_csv_pets, filename: 'pets.csv'
  end

  def export_clients
    @clients = Client.all
    send_data @clients.to_csv_clients, filename: 'clients.csv'
  end

I have it in the application controller because I used it in multiple different areas including creating single CSV exports and creating complex zip files with multiple zips and CSVs inside.

Some things that I have tried to cleanup the code include:

  • Different variables of this:
    def csv_export (model, filename)
    @model.pluralize = (model.titleize).all
    send_data @model.pluralize.filename, filename: filename
    end
  • Having each one in its own controller (could not access them from different views and other controllers easily)
  • I also tried to figure out how to create my own module, but was unable to do so.

My application record is just as bad with repeated lines simply meant to export the CSVs:

      def self.to_csv_appointments
        attributes = %w(appointment_id location_id employee_id client_id child_id notes 
        has_specific_employee start_time end_time)
        CSV.generate(headers: true) do |csv|
          csv << attributes
          all.each do |appointment|
            csv << attributes.map { |attr| appointment.send(attr) }
          end
        end
      end
    
      def self.to_csv_appointmentservices
        attributes = %w(appointment_id service_id price duration)
        CSV.generate(headers: true) do |csv|
          csv << attributes
          all.each do |appointment|
            csv << attributes.map { |attr| appointment.send(attr) }
          end
        end
      end

      def self.to_csv_tickets
        attributes = %w(ticket_id location_id client_id ticket_status employee_id 
        employee_id start_time)
        headers = %w(ticket_id location_id client_id status employee_id 
        closed_by_employee_id closed_at)
         CSV.generate(headers: true) do |csv|
         csv << headers
          all.each do |appointment|
           csv << attributes.map { |attr| appointment.send(attr) }
          end
        end
      end

For the application record, I have tried similar methods as those listed for the application controller, but to no avail. Again, I use the code in application record instead of in the individual model files because I need to access these in multiple parts of the site.

The code from the application controller is used mostly in the static controller and buttons on the view files. I need the ability to create the file sets, as listed below, but also allow the user to export just one CSV.

Examples from static controller to built the zip files:

def create_appointments_zip
  file_stream = Zip::OutputStream.write_buffer do |zip|
    @appointments = Appointment.order('service_id')
    zip.put_next_entry "appointment_manifest.csv"; zip << File.binread("#{Rails.root}/app/assets/csvs/appointment_manifest.csv")
    zip.put_next_entry "appointments.csv"; zip << @appointments.to_csv_appointments
    zip.put_next_entry "appointment_services.csv"; zip << @appointments.to_csv_appointmentservices
    zip.put_next_entry "appointment_statuses.csv"; zip << @appointments.to_csv_appointmentstatuses
  end
  file_stream.rewind
  File.open("#{Rails.root}/app/assets/csvs/appointments.zip", 'wb') do |file|
    file.write(file_stream.read)
  end
end

 def export_salonset
    create_appointments_zip
    create_tickets_zip
    create_inventory_zip
    create_memberships_zip
    file_stream = Zip::OutputStream.write_buffer do |zip|
      @saloncategories = Saloncategory.all
      @salonservices = Salonservice.all
      @clients = Client.all
      @locations = Location.all
      @salonpricings = Salonpricing.all
      @staffs = Staff.order("location_id")
      zip.put_next_entry "batch_manifest.csv"; zip << File.binread("#{Rails.root}/app/assets/csvs/batch_manifest_simple_salon.csv")
      zip.put_next_entry "categories.csv"; zip << @saloncategories.to_csv_saloncategories
      zip.put_next_entry "clients.csv"; zip << @clients.to_csv_clients
      zip.put_next_entry "employees.csv"; zip << @staffs.to_csv_staff
      zip.put_next_entry "locations.csv"; zip << @locations.to_csv_locations
      zip.put_next_entry "pricings.csv"; zip << @salonpricings.to_csv_pricings
      zip.put_next_entry "services.csv"; zip << @salonservices.to_csv_salonservices
      zip.put_next_entry "appointments.zip"; zip << File.binread("#{Rails.root}/app/assets/csvs/appointments.zip")
      zip.put_next_entry "inventories.zip"; zip << File.binread("#{Rails.root}/app/assets/csvs/inventories.zip")
      zip.put_next_entry "tickets.zip"; zip << File.binread("#{Rails.root}/app/assets/csvs/tickets.zip")
      zip.put_next_entry "addonmappings.csv"; zip << File.binread("#{Rails.root}/app/assets/csvs/addonmappings.csv")
    end
    file_stream.rewind
    respond_to do |format|
      format.zip do
        send_data file_stream.read, filename: "salon_set.zip"
      end
    end
    file_stream.rewind
    File.open("#{Rails.root}/app/assets/csvs/salon_set.zip", 'wb') do |file|
      file.write(file_stream.read)
    end
  end

Link to my repository, if that is helpful
https://github.com/atayl16/data-wizard/blob/master/app/controllers/application_controller.rb
https://github.com/atayl16/data-wizard/blob/master/app/models/application_record.rb

I know there must be a better way than writing these same lines over and over. The code works, my site works (amazingly), but I would be embarrassed for any seasoned developer to see the repository without laughing. Any help is appreciated!

bip 32 hd wallets – Generate addresses from Trezor’s xPub using Python

I am trying to generate BIP32 HD addresses from my Trezors xPub key.
I keep getting errors with most of the libs our there. What am I missing?

pywallet:

from pywallet import wallet
xpub = 'ypub6Y9NsCaunfAtedv6VX7UTfuvQGLu1TgMtLtjnRydESqWwUSkJnAzATyCzscezpcfoXtgJhAfUTauEQWWt8xvbLxo7qXToCDkJi1Nb1b7wZB'
wallet.create_address(network="BTC", xpub=pub, child=0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/pywallet/wallet.py", line 48, in create_address
    wallet_obj = Wallet.deserialize(xpub, network=network.upper())
  File "/usr/local/lib/python3.5/dist-packages/pywallet/utils/bip32.py", line 557, in deserialize
    version)
pywallet.utils.keys.IncompatibleNetworkException: Incorrect network. Bitcoin Main Net expects a byte prefix of 76067358, but you supplied b'x04x9d|xb2'

The pybitcointools do generate an address, but they do not match the one Trezor generates.

Essentially I need code which replicated Trezor address generation from xPub. Any ideas?

scripting – Generate SQL scripts in powershell

I have written a little function in Powershell that applies a driver table to a template in order to produce a simple repetitive result. It was really a learning exercise to help me become proficient in Powershell.

Here is the function:

 <#
.NOTES
    Script: Expand-Csv    Rev:  3.2
    By:     DGC           Date: 2-21-19
.SYNOPSIS
    Generates multiple expansions of a template,
    driven by data in a CSV file.
.DESCRIPTION
    This function is a table driven template tool. 

    It generates output from a template and
    a driver table.  The template file contains plain
    text and embedded variables.  The driver table 
    (in a csv file) has one column for each variable, 
    and one row for each expansion to be generated.
#>
function Expand-csv {
    (CmdletBinding())
    Param (
       (Parameter(Mandatory=$true))
       (string) $driver,
       (Parameter(Mandatory=$true))
       (string) $template
    )
    Process {
       Import-Csv $driver | % {
           $_.psobject.properties | % {Set-variable -name $_.name -value $_.value}
           Get-Content $template | % {$ExecutionContext.InvokeCommand.ExpandString($_)} 
       }
    }
}

Expand-Csv takes two inputs. The first is a CSV file that represents the driver table. In this example, the csv file might look like this.

privs,table,user
ALL,Employees,DBA
READ,Employees,Analyst
"READ, WRITE", Employees, Application
ALL,Departments,DBA
READ,Departments,"Analyst, Application"

The template might look like this:

grant $privs 
   on $table 
   to $user;

The result of running it through Expand-Csv might look like this:

grant ALL 
   on Employees 
   to DBA;


grant READ 
   on Employees 
   to Analyst;


grant READ, WRITE 
   on Employees 
   to Application;


grant ALL 
   on Departments 
   to DBA;


grant READ 
   on Departments 
   to Analyst, Application;

This result is fed down the pipeline, but it could easily be written to a file for later execution by SQL.

A superior tool might be written that takes as input a table or view in a database instead of a .CSV file. I wanted to do the easy stuff first.

I apologize for the fact that the code is not easy to read. I was interested in minimizing the use of variables inside it, so I used $_ in more than one context. At least it’s small.

You may be able to use this tool as a starting point to develop something that will make your workload easier. I hope so.

magento2, how correctly generate oauth_signature

how correctly generate oauth_signature for magento2 auth1.0 API?
how to generate oauth_signature correctly ,because the key that is oauth_signature generated from me is constantly different from the one that oauth_signature generates the magento2

website design – Why people use AdobeXD if it cannot generate (reasonably well structured) HTML and CSS?

What does it do

Adobe XD is a wireframing and prototyping tool to visualize ideas. It makes it easy to quickly visualize an idea for an interface and build a simple clickdummy to test the interaction with other people.

Ways to export for development

Yes, it is true that a full export is very bloated and not very human readable. But this is also true for a lot of GUI builders out there (e.g. Stackoverflow question about Netbeans GUI Builder for Java). You still need a human to code a layout that is minimalistic and human readable.

I found that the following things help me a lot:

  1. Export as svg and then copy it into your HTML.
  2. Share prototype and then use the development view to inspect css styles

Adobe XD is similar to other wireframing programs such as Figma or Sketch. I am also in no way affiliated with Adobe.

Elixir generate inverted / reversed map

I would like to transform the input

elems = (a, b, c)
terms = (t1, t2)

@spec contains?(term, elem) :: boolean
def contains?(term, elem), do: #implementation

to either of

%{t1 => (a, b), t2 => (c)}

or

%{t1 => (a), t2 => (b, c)}

where

t1 |> contains?(a) #=> true
t1 |> contains?(b) #=> true
t1 |> contains?(c) #=> false

t2 |> contains?(a) #=> false
t2 |> contains?(b) #=> true
t2 |> contains?(c) #=> true

My current solution is as follows

defmodule Test do
  def contains?(term, elem) do
    elem in term
  end

  def test do
    elems = (1,2,3)
    terms = ((1,2), (2,3))
  
    elems
    |> Enum.into(%{}, fn elem ->
      {elem,
       terms |> Enum.find(&contains?(&1, elem))}
    end)
    |> reverse_map()
  end

  defp reverse_map(map, reversed \ %{})
  defp reverse_map(map, reversed) when map_size(map) == 0, do: reversed

  defp reverse_map(map, reversed) do
    (key | _) = Map.keys(map)
    {value, map} = Map.pop!(map, key)
    reversed = Map.update(reversed, value, (key), &(key | &1))
    reverse_map(map, reversed)
  end
end

With this solution I’m generating the map

%{a => t1, b => t1, c => t2}

then reversing it and collecting collisions in a list.

But I feel this intermediate map is unnecessary and a solution could exist without it.

In addition I’m not sure my implementation of reverse_map is as elegant as it could be.

Generate custom code from registration form

I need to generate a custom code, kind of a hash code, from a field received in a form.

The code would be a function calculated from this particular field (a 6-digit number), and it has a few limitations: It has exactly 4 digits, and all digits must be between “1” and “3”… for instance “3221”, “1431”, etc. I already have the formula in an excel-like format. It´s OK if different field values return the same code in some cases.

How can I make this custom function to read the field from the form, calculate the code with my formula, and show it to the user or send it by e-mail? Is it feasible?

Thanks in advance!

PHP – What is the best library to generate thumbnail images?

I am looking for a library to help me generate thumbnails of images on the front end; Scenario: The images are already on the server; I just want them to appear as specified, example: thumb.php? src = {link} & w = 200px100px

dnd 5e – Can Alchemists Experimental elixirs be combined to generate a roll on the potion miscibility table in the DMG?

The rules for mixing potions is a variant rule that a DM has the option to use if they want. The optional rules state:

A character might drink one potion while still under the effects of another, or pour several potions into a single container. The strange ingredients used in creating potions
can result in unpredictable interactions. When a character mixes two potions together, you can roll on the Potion Miscibility table. If more than two are combined, roll again for each subsequent potion, combining the results.

This is a general rule for combining potions and does not specify any limitation with regard to where the potions come from or how they were made. As such, any potion that the Artificer makes can be used in conjunction with the optional rule for mixing potions.

However, because the rule is optional, it is up to the DM to decide if the rule can be used so check with them.