What is a way to create a unique name for a file given it's name and a namespace value in the same directory? - file

I have to create a file name for a file that will exist with other files with the same or similar name in the same folder.
I have two values that will be used to define the name. The namespace and the class name.
So if there are a team of users and user A creates a Person class they have to give it a unique namespace name so if user B creates a Person class does not conflict with user A's class name.
Traditionally, namespaces are defined something like,
com.amazon.category.people
http://www.amazon.com/2022/categories/7.0.0
I'm ok with joining the namespace with the class name to create a unique phrase like so:
com.amazon.category.people::Person
BUT Here's the problem. When I'm creating a file, the filesystem doesn't like all those dots or colons Actually, I don't like them because multiple reasons. I thought about replacing all dots and colons with underscore.
com_amazon_category_people_Person.json
That's the best I've come up with. It won't work well with the other type of namespace:
http___www_amazon_com_2022_categories_7.0.0_Person
Are there any answers this problem?

Names containing dots aren't a problem for any OS, as far as I know. What you can do is either:
Put the files in a folder hierarchy, where every folder is the name of a namespace segment, like this:
+-me
| +-topchetoeu
| | +-myprogram
| | +-Program.json
| +-somebodyelse
| +-calculator
| +-Add.json
| +-Subtract.json
| +-Divide.json
| +-Multiply.json
+-com
+-microsoft
+-windows
+-Spyware.json
Another solution would be to separate the namespace segments with dashes, and the class name with a # symbol, resulting in something like this:
me-topchetoeu-myprogram#Program.json
me-somebodyelse-calculator#Add.json
me-somebodyelse-calculator#Subtract.json
me-somebodyelse-calculator#Divide.json
me-somebodyelse-calculator#Multiply.json
com-microsoft-windows#Spyware.json
etc...

Related

AD User Array CSV search and analyze error

i want to search to an exported Active Directory list but i got one problem.
AD Files looks like this and its saved as CSV-File (I added a Header to the file)
CN=ARV-PRO7,OU=etc,OU=etc,DC=etc,DC=etc,DC=etc
CN=BLAPO86z,OU=etc,OU=etc,DC=etc,DC=etc,DC=etc
This is a example (there are 37 more entrys like ARV in the "where" is shoreted it for better view) of the Code im trying to run:
$Datei = Import-Csv "C:\FILESPATH\AD-list.csv"
$Datei | where {$_.CN -notmatch "ARV" -and $_.CN -notmatch "BBN"} | Out-GridView -Title "Site Info"
This shows me all the items with no ARV in it, thats what i want.
BUT it ignores also the items which looks like this:
CN=PR122ARVO7,OU=etc,OU=etc,DC=etc,DC=etc,DC=etc
Because ARV is in the name the item is not shown.
I need a way to check if the first 3 letter ARV than its okay and he can ignore it but i also need him to show me names with ARV in it to check the name rules. ( Department-PCNAME ) and not (BLABLA-PC-DEPARTMENT-NAME)
I Hope its clear what iam asking and what my problem is ^^
If I understand correctly, you would like to ignore items starting with ARV. This should work (simplified, only where section is important here):
#{CN='ARV-PRO7'},
#{CN='BLAPO86z'},
#{CN='PR122ARVO7'} | where { !$_.CN.StartsWith('ARV') }

filling attribute with concatenated string

I am looking for a way to concatenate a string and put it in one active directory user account object, to be precise, in altsecurityidentities.
The value to be input will be as following:
" which is constant, and (firstName)(whitespace)(lastname) (custom value which can be taken from another attribute, which is in form x.yyyyyyyy.z (what matters to me is yyyyyyy part (.substring(2,8)) works like charm here.
I'd like to do it for several accounts that are listed in variable of type TypeName: Microsoft.ActiveDirectory.Management.ADUser.
So that it can be set for all accounts under $accounts variable.
So far I have the code to create the attribute value for one account listed in there:
$accounts | %{'constant value'+$.givenname+' '+$.surname+' '+'('+$(($_.attributename).substring(2,8))+')'}
This, i'd like to put in altsecurityidentities attribute value, log to event viewer success and errors
You're almost there really just need to apply the value to the desired field:
$accounts | ForEach-Object { Set-ADUser -Identity $_ -Add #{altsecurityidentities = "constant value $($_.givenname) $($_.surname) ($($_.attributename.substring(2,8)))"} }
I have tidied up your code by embedding the variables in a string rather than using concatenation, which is much cleaner.

Save file on disk with name based on title of object

If in Yii 1.1.x there is some extension, to create valid file system(linux) name from object title with unique name, like a slug, but with unique name in given directory ?
I mean I want to save file on disk with name based on title of object.
Thanks!
Actually I would like a bit more :
1) In title of object all illigel chars(for Linux/windows OS) and space must be converted to '-'
2) if there is such file add valid counter for it , like "_45"
Maybe that not yii extension, but some php function.
The simplest way - you can add object id to prefix of file. Then your file names always be uniqueness. For example:
1-title-first
2-title-first
3-title-second
you can use php own uniqueid() to generate unique ids!
$title = uniqid('wp_'); // have wp_ prefixed for title

Renaming Xcode Header and Implementation files

I was wondering if, in Xcode, it was possible to find and change all references to the name of a header file, and chage it with something else and still have it work, what I mean is find a name like this: , and have it find all references to it like this: , and this: and replace them with the new name. Thank you
You can rename a class with the "Refactor" function in Xcode:
Select the class name "BlueJaysViewController" in "#implementation BlueJaysViewController".
Choose Edit -> Refactor -> Rename ...
Enter the new class name and select "Rename related files"

Ruby delete_if block

This is using Ruby 1.9.
I have a delete_if block:
#logHash[date].delete_if{ | logItem | logItem.name == name }
Where logItem.name is the name of the logItem and name is the name of the logItem I'm looking for. This works fine, except it deletes each logItem with the specified name. Is there a way to find the first item with an equal name and only delete that? So if there are two logItems that have the same name, I only want to delete one of them. Any ideas?
I'd use Array#index to find the index of the first item which had a matching name, and then Array#delete_at to delete it.
index_to_delete = #logHash[date].index {|log_item| log_item.name == name}
#logHash[date].delete_at(index_to_delete)

Resources