name every column in a table excel/vba

vba
Question: I am trying to name each column in an excel spreadsheet by their header. For instance, if a column has the header "cat" I want the column to be named "cat". That way I can refer to cat in a formula, rather than specifying the column with A:A. I can do this just fine with a single column, but when I try to do it with many my procedure fails. Here's my code. Sub defineName() Dim numColumns As Long Range("A1").Select numColumns = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column Columns("A:A").Select For cat = 0 To numColumns Selection.Offset(0, I).Select ActiveWorkbook.Names.Add Name:=cat1, RefersToR1C1:="activesheet.cat1" Next cat End Sub Im pretty sure my problem is this part Name:=cat1, RefersToR1C1:="activesheet.cat1" and it is not iterating like I think it is. I almost wish I could Name:=[cat]1, RefersToR1C1:="activesheet.[cat]1" but that…
Read More

Perlin noise looks too griddy

Uncategorized
Question: I've written my own perlin library and have also used one of the standard python libs for generating noise. This is the code I have bellow:import sys from noise import pnoise2, snoise2 perlin = np.empty((sizeOfImage,sizeOfImage),dtype=np.float32) freq = 1024 for y in range(256):for x in range(256):perlin[y][x] = int(pnoise2(x / freq, y / freq, 4) * 32.0 + 128.0) max = np.amax(perlin) min = np.amin(perlin) max += abs(min) perlin += abs(min) perlin /= max perlin *= 255 img = Image.fromarray(perlin, 'L') img.save('my.png') dp(filename='my.png') The image it generates is: Regardless of the frequency or octaves, it always looks gritty. It is my conclusion that I am thus using it wrong, but I'm not sure why my solution is wrong. I use fractional units via frequency and iterate through my 2d array. I've…
Read More

JPanel contents are not getting printed

Uncategorized
Question: I have JPanel with group layout set as a layout. Now, I want to print all of it's elements but it's printing blank page. I tried to print a button once without JPanel and it worked using same code. I have implemented Printable interface in my JPanel class and have overridden print() shown below. public int print(Graphics g, PageFormat pf, int index) throws PrinterException { Graphics2D g2 = (Graphics2D) g; if (index >= 1) { return Printable.NO_SUCH_PAGE; } else { panel.printAll(g2); return Printable.PAGE_EXISTS; } } I am not sure what I am doing wrong. Answer: Read more
Read More

In PHP, how can I remove items in an array whose keys are found in another array conveniently?

Uncategorized
Question: I have two arrays:$array = new Array('id'=>1, 'name'=>'Peter', 'sex'=>'male', 'age'=>25); $excludes = new Array('sex', 'age'); I want to get the following result:$array = new Array('id'=>1, 'name'=>'Peter'); The items whose keys are found in the array $excludes are removed. How can I achieve this conveniently? Answer: Simply with array_diff_key and array_flip functions:// $arr is your initial array (besides, don't give `$array` name to arrays) $result = array_diff_key($arr, array_flip($excludes)); print_r($result); The output:Array ( [id] => 1 [name] => Peter ) Read more
Read More

Ferginse – Responsive Retina Landing Template

Uncategorized
A simple and beautiful template with full adaptability and correct code. It is very easy to change and will suit any subject. In the template there are different colors for different taste and theme. We are supporting in 99% of browsers since 2011 and Retina displays. The template is based on the Bootstrap grid (1170px), very simple, stylish and multithematic. Easily editable and perfectly structured. + PSD
Read More

SWIFT 3 – I need to create a way to select a relation to an item and then save it

Uncategorized
Question: I need to create a way to get the selected value from the Table view as a relationship to the text entered in the UITextField and save when clicking the save button. Here are the way i organized the views and the code: Views and what i need to do Data Model This is the view controller to the add view. import UIKit class addDisciplinasViewController: UIViewController, UITextViewDelegate { let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext var materias: [Materia] = [] var selectedIndex: Int! var filteredData: [Materia] = [] var teste = ["teste","teste2"] func fetchData() { do { materias = try context.fetch(Materia.fetchRequest()) filteredData = materias } catch { print("Couldn't Fetch Data") } } override func viewWillAppear(_ animated: Bool) { fetchData() } var selectedMAT: String? @IBOutlet var itemEntryTextView: UITextView? @IBAction func cancel(_…
Read More

Is it possible to delete a dereferenced Pointer

Uncategorized
Question: I have some legacy code where a Object is dynamically allocated and then emitted:QList *list = new QList(); ... emit listReady(*row); void OtherClass::slotList(QList list) { ... delete list??? } i can delete the objects in the list and i can clear the List, is it possible to delete the list itsef in my slot? Answer: is it possible to delete the list itsef in my slot? No, it's not possible. Because your slot accept the list by value, which is copy of original QList *list object. void OtherClass::slotList(QList list) To be able delete the list object you should change the slotList arguments to accept the pointer to list. Read more
Read More

invalid literal for int() with base 10: – django – python

python
Question: I was trying to make the author of a news be automatically picked when the news is created. This is my code: Model:from django.db import models from ckeditor.fields import RichTextField from django.contrib.auth.models import User # Create your models here. class News(models.Model):news_title = models.CharField(max_length=420, help_text="Insert only the news title, be specific and short!") pub_date = models.DateTimeField('date published') article_text = RichTextField() news_author = models.CharField(User, max_length=250, editable = False, default='unknown') class Meta:ordering = ["news_title", "-pub_date"] verbose_name = "News" verbose_name_plural = "News" def get_absolute_url(self):return reverse('model-detail-view', args[str(self.id)]) def __str__(self):return self.news_title Admin:from django.contrib import admin # Register your models here. from .models import News admin.site.site_header = "SoLS UCP Admin Panel" class NewsAdmin(admin.ModelAdmin):list_display = ('news_title', 'pub_date', 'news_author') def save_model(self, request, obj, form, change):if getattr(obj, 'news_author', None) is None:obj.news_author = request.user obj.save() admin.site.register(News, NewsAdmin) The thing is…
Read More

ng-repeat input keeping same value for each loop

Uncategorized
Question: I have an ng-repeat with a comment input inside the loop. With a ng-model="comss.comment", however when I start to type on the first input, I can see the typing on the 2nd and all of the other inputs. How can I stop this? I've tried adding a name with a unique ID however that did not work. Here is my code: Run code snippetHide results Expand snippet Answer: Since you're in a loop, accessing comss.comment for each loop is going to be the same model, you need to modify your template and the model slightly: In the controller it would be a larger object, so for a loop of two items in discoverloaded, you would have this in comss:comss = { 0: { comment: '' }, 1: { comment:…
Read More

Terraform: Assign resource attribute to resource argument using If/Else pattern

azure
Question: I am using the IF/ELSE pattern in Terraform to build a NIC with or without a public IP. The problem comes when assigning the NIC. I can't find a technique that lets me choose the resource that was used to create the NIC (with or without public IP). Using ternary operations fail because one of the resources doesn't exist. Putting the resources in a list doesn't interpolate. How do I assign the correct resource output? resource "azurerm_public_ip" "public_ip" { count = "${var.assign_public_ip}" name = "${format("${var.name}-pip%02d", count.index)}" location = "${var.location}" resource_group_name = "${var.resource_group_name}" public_ip_address_allocation = "static" tags { environment = "${var.resource_group_name}" } } resource "azurerm_network_interface" "nic_with_public_ip" { count = "${var.assign_public_ip}" name = "${format("${var.name}-nic%02d", count.index)}" location = "${var.location}" resource_group_name = "${var.resource_group_name}" ip_configuration { name = "ip_cfg" subnet_id = "${var.subnet_id}" private_ip_address_allocation =…
Read More

Ag-Grid require delete button for each row

Uncategorized
Question: I am trying to implement a solution with ag-grid and not got stuck into a problem. I am trying to implement edit and delete button in each row .edit button implementation is successful but problem is with delete button. I have tried best of my knowledge (which is little for angular 2) .Please see the implementation as per below code:- court.component.ts import { Component } from '@angular/core'; import { Court } from './court.model'; //import './../utils/array.extensions'; import { GridOptions } from "ag-grid"; import { DataCourtService } from '../services/data-court.service'; import { EditButtonComponent } from "../utils/editbutton.component"; @Component({ selector: 'court', template: require('./court.component.html'), providers: [DataCourtService] }) export class CourtComponent { private gridOptions: GridOptions; public courts : Court[]; onQuickFilterChanged(event: any) { this.gridOptions.api.setQuickFilter(event.target.value); } constructor() { var courtservice = new DataCourtService(); this.gridOptions = { rowSelection: 'single'…
Read More

Email notification to user is not sent when ClientUserId is provided

Uncategorized
Question: I'm trying to create envelope from template i uploaded to my account. Using following code to do that:public static void main(String[] args) throws ApiException { // Enter your DocuSign credentials String UserName = "my-user-name"; String Password = "my-password"; String IntegratorKey = "my-integrator-key"; // for production environment update to "www.docusign.net/restapi" String BaseUrl = "https://demo.docusign.net/restapi"; // initialize the api client for the desired environment ApiClient apiClient = new ApiClient(); apiClient.setBasePath(BaseUrl); // create JSON formatted auth header String creds = "{"Username":"" + UserName + "","Password":"" + Password + "","IntegratorKey":"" + IntegratorKey + ""}"; apiClient.addDefaultHeader("X-DocuSign-Authentication", creds); // assign api client to the Configuration object Configuration.setDefaultApiClient(apiClient); //////////////////////////////// LOGIN START // login call available off the AuthenticationApi AuthenticationApi authApi = new AuthenticationApi(); // login has some optional parameters we can set AuthenticationApi.LoginOptions loginOps = authApi.new…
Read More

Account Payables for the same Partner in OpenERP

openerp-7
Question: I'd like to know how I can utilize OpenERP fully in term of doctor commission payouts. Ideally, I'd like to know the breakdown of the commission of a doctor (from consultation / visiting in-patient / operation, etc). An example: The consultation fee is USD 100, the USD 60 will go as hospital income while the remaining USD 40 goes to the doctor as a commission fee. From the above example I try to do it this way I split the consultation fee to two products, Hospital Fee is USD 60 and the Doctor Fee is USD 40. For Hospital Fee I set the income account to "a hospital income", while Doctor Fee I set the income account to "a payable doctor fee". This way once the sale order is…
Read More