Python regex, how to search for multiple strings?

Question: I'm new to python and am trying to figure out python regex to find any strings that match -. For example, 'type1-001' and 'type2-001' should be  a match, but 'type3-asdf001' shouldn't be a match. I would like to be able to match with a regex like [type1|type2|type3]-\d+ to find any strings that start with type1, type2, or type3 and then are appended with '-' and digits. Also, it would be cool to know how to search for any upper case text appended with '-' and digits.
Here's what I think should work, but I can't seem to get it right...
pref_num = re.compile(r'[type1|type2]-\d+')

Comment: Just FYI here, but a regex that searches for multiple strings is kind of redundant, as the whole point of a regex is to search for multiple strings. If you were only searching for one string, you could test for membership with `in`, and the match would simply be the string itself.
Comment: @TigerhawkT3 Not really. I can give you regexes that search for a single static string but includes multiple conditions that are not possible using a simple text search.
Comment: @poke nailed it, my example is simplified, but i need to search for single static strings that include multiple conditions that aren't possible with simple text search (without keeping/updating a list of all of those strings)
Answer: [] will match any of the set of characters appearing between the brackets. To group regexes you need to use (). So, I think your regex should be something like:
pref_num = re.compile(r'(type1|type2)-\d+')

As to how to search any uppercase text appended with - and digits, I would suggest:
[A-Z]+-\d+

Comment: Thanks, this answers both of my questions. Perfect. Also, the () vs [] was key to matching the group regex.
Answer: If you only want the digit after "type" to be variable then you should put only those in the square brackets like so:
re.compile(r'type[1|2]-\d+')

Answer: You can use the pattern
'type[1-3]-[0-9]{3}'

Demo
>>> import re
>>> p = 'type[1-3]-[0-9]{3}'
>>> s = 'type2-005 with some text type1-101 and then type1-asdf001'
>>> re.findall(p, s)
['type2-005', 'type1-101']

Answer: pref_num = re.compile(r'(type1|type2|type3)-\d+')

m = pref_num.search('type1-000')
if m != None: print(m.string)

m = pref_num.search('type2-000')
if m != None: print(m.string)

m = pref_num.search('type3-abc000')
if m != None: print(m.string)


installing terraform on CentOS

Question: How do I get my terrfaform installation working on centos properly?
The only way for me to run terraform commands is if I add the path to the terraform executable.
Answer: You can follow this Installation steps of Terraform for CentOS/RHEL.
Install yum-config-manager to manage your repositories.
$ sudo yum install -y yum-utils

Use yum-config-manager to add the official HashiCorp Linux repository.
$ sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo

Install.
$ sudo yum -y install terraform

For complete reference you can follow this Install Terraform documentation.

installing terraform on CentOS


The Elusive sign of + in organ fingering

Question: I am a pianist trying to learn organ and since there's no funds for lessons I am reading old organ instruction books and came across one from Schneider in the public domain in London published 1875 that has weird signs of "+" for scale fingerings but this plus sign doesn't mean a sharp or altered note as in figured bass and I can't understand what it means although I think it is a sign notated in old clavier scores, also.
It's like my mind has left me with this. Is anyone able to help me out here?
Comment: related question: [What does "x" mean in piano fingering?](https://music.stackexchange.com/questions/62802/what-does-x-mean-in-piano-fingering).
Answer: From memory (many decades ago!) the + indicated use of thumb. Index finger was 1, middle 2, and so on.
Answer: In old advertisments for piano music (and particularly piano methods) you will see a choice of 'English fingering' and 'Continental fingering'.    English used X for the thumb.
Note the emphasis on 'Easy'.  Vain promises of instant gratification are nothing new!
Comment: I think you have this backwards. "Continental fingering" means the 12345 system which is now (as far as I know) standard everywhere. "English fingering" is the +1234 system (+ for thumb, and fingers 1 to 4) which had pretty much disappeared except for "old scores" when I started piano lessons in 1950-something.
Answer: Tim is right. I had the same experience with old baroque guitar sheet music too where the "+" marked the thumb for the right or left hand.
Comment: Using the thumb on the fretting hand, for classical guitar playing? Plucking hand is usually marked 'p' (pulgar) for thumb.
Comment: Yes indeed. Some years ago I found some teaching material from Matthäus Waissel "Lautenbuch, darinn von der Tabulatur und Applikation der Lauten gründlicher und voller Unterricht" from about 1592. He liked putting his thumb on the lowest (lute) string in some cases and marked this with an "x". I play my ukulele this way, too.
Comment: Surprising. I'd have thought he'd have been ex-communicated, or burnt at the stake at least for that in those days !
Comment: @Tim a lute isn't a guitar. Some baroque lutes had as many as 12 courses of strings, and most of them were pairs of strings like a 12 string guitar, so there were actually 24 strings! You need all the digits you can use, on a fretboard that big.


Can't change the font size of custom link menu

Question: I've created a custom menu titled SANDUSKY with no-hover as css classes. It is align with HOME,ABOUT,GALLERY,STORE,CONTACT which are the navigation menus. I wanted to customize SANDUSKY, I was able to change the color and font but I cannot increase or make it bigger, the size is just the same with the navigation menus.
Below is the code I used.

.no-hover a:link {
  color: none !important;
  font-size: 50px;
}

.no-hover a:visited {
  color: none !important;
}

.no-hover a:hover {
  background-color: transparent !important;
}

.no-hover a:active {
  color: none !important;
}

.no-hover {
  position: absolute;
  left: -70px;
  font-family: lucida handwriting;
  font-weight: bold;
  font-style: italic;
}

SANDUSKY

Comment: @MrShemek: it is best to encourage people to put the problem details in the question itself. If people were to start offering links to broken websites, the question would no longer make any sense as soon as the site was fixed.
Comment: Please include your HTML, thanks
Comment: Include it in the post above not in comments.
Comment: Do you have a website URL we can check? Probably there is CSS rule that overwrites your changes but it is hard to guess.
Comment: I think you are trying to reduce the font-size right?
Comment: Your font-size: 90px; in the .no-hover a:link  is overwriting the
font-size: 50px!important; in .no-hover. Just remove the, 90px and it should be fine.
Comment: @KalaiselvanA - I'm trying to increase the font-size.
Comment: @ Highdef - I changed the code removing 90px but still the same.
Comment: @MarkDaniel you are trying to increase the font-size hover or what?
Comment: @KalaiselvanA - a:link class
Answer: font-size: 14px; & font-size: 16px; I have changed this two font-size in below code

.no-hover a:link {
  color: blue !important;
  font-size: 150px;
}
.no-hover a:visited{
  color: none !important;
}
.no-hover a:hover {
  background-color: transparent !important;
}
.no-hover a:active{
  color:  none !important;
  font-size: 130px;
}
.no-hover {
  position: absolute;
  left: -100px;
  font-family: lucida handwriting;
  font-weight: bold;
  font-style: italic;
  font-size: 50px!important;
}

SANDUSKY

Comment: You do realize that the output can't be seen because of the absolute position of -100px and I think the OP was trying to change the font size in .no-hover class and not the .no-hover a:link class.


How to improve/solo over a song/backing track besides staying in key?

Question: I recently bought an electric guitar and am looking to start soloing/playing along songs/backing tracks - I have learnt all positions of the pentatonic scale, know a handful of licks and have a basic knowledge of music theory. My question is, what's the next step? I'm having a hard time playing along to anything other than blues, and even with that I feel my approach is rather random - I pay no consideration whatsoever to what the chords are - and I wouldn't know what to do differently at a given point even if I knew what chord was playing. Or what to do differently given the genre/tempo/rhythm of the backing track. I appreciate that this question is very vague, but I feel clueless and would appreciate any advice at all!
Thank you!
Answer: Different people have different approaches to improvisation.
Some people like to analyse the chord progression, work out what scales fit, what points in the chord progression to switch scale, and play within those.
If you feel that fits your brain, get books on harmony, exercise yourself by analysing songs yourself, then practice improvisation using your analysis as a basis. With practice, the analysis step will be pretty quick.
Other people take a more intuitive approach, in which they can feel in their head what they want to play, and play that. If you can sing an improvised solo, then maybe the intuitive approach is what suits you.
Try singing a phrase then replicating it on the guitar. Go as slowly as you like, and retry after mistakes. With practice you'll learn to do it right, and at tempo, every time.
Once you can do that, try improvising to a backing track. Try and sing the same melody as you're playing -- this proves to yourself that you're playing what you intend to play -- rather than just hitting notes from the scale without really knowing what it'll sound like until it comes out.
Answer: Take a look at the chords you are playing over. If you have a blues, which usually is the I IV V progression, then play a chord/scale relationship. Get familiar with arpeggios of the chord you are playing over. Use notes from the major/minor pentatonic scales and mix with the arpeggio. Connect an A7 chord to a D7 chord by using the 3rd of A7 (C#) to the flat 7 (C) of the D7 chord. Notice the smooth transition in your solo by following chord tones as the chords change.
Also listen to your favorite solos and try ideas from them to the backing tracks. Learn a lick and apply in different keys.
Answer: As always, a lot of practice is the fundament of improving, especially when it comes to soloing and improvising in my my opinion. Things that have helped me a lot when I was at your point:

Listen to guitar solos as often as you can. Learn to play some of them which you like the most, and try to 'steal' some of the licks and runs the next time you're improvising
Record your own backing track - if you have a looper than this is really fun. Start with the most simple vamps, for example just Am - G all over again. Then start playing, and listen to how the notes sound over the different chords. Add / replace a chords of you're backing track and start over again. This really helped me a lot more than just reading "dont play this note over this chord" stuff. (Which can be helpfull though, too).
For the beginning, stay in one area on the fretboard. For example the A-Minor Pentatonic on the 5th Fred. Then when you feel like you've got some cool stuff to play, 'fill up' the pentatonic scale with the minor scale notes. Again, try to listen where they fit in and where they just don't. If you're done, move on the A-Minor scale beginning on the 8h fret, do the same again, and then combine these two.

As you do that regullarly, you will soon notice that you're improving. The most important thing you'll be learning, is to hear your solo before actually playing it. Over time, you'll know how which note will sound at which point of the song, and this where you really get creative in creating your own stuff, rather than playing around and notice afterwards "wow, that sounded quite cool, how did I do that?"
Answer: Your next step is to find a recording of a guitar solo that you like and learn it by ear. Play it with the recording over and over again and try to sound exactly like it.
Then, find another recording of a guitar solo that you like and learn it by ear.  Play it with the recording over and over again and try to sound exactly like it.
Then, find another recording....
Answer: There's still some learning to be done ! If you're aware that the pentatonic notes cover both a major key and its relative major, there are two options of notes to use. Note that playing the minor notes over a major sequence works far, far better than the other way round.Or match them properly.
Two other scales which are invaluable are the full major and its relative minor (both using the same notes as each other, just centred differently).As in, the Em scale notes will also work in the key of G major.
With the major, starting on different notes from it will give you the modes, each of which has a different 'flavour'. See elsewhere on this site for really clear explanation of how these can be used. This bit opens up a whole new can of worms though.
Work on the theory side and be aware that most songs/tunes will contain notes from the particular chord that's currently being played. I.e. in a couple of bars that contain, say, B,B,G#,E,F#,G#, the accompanying chord will most likely be E major.Turn this around, and it's clear that in a bar of E (chord), playing some, all, or even one  of the chord tones will keep the tune matching the chord. Not many existing songs will have notes in a particular bar that don't come from the accompanying chord. If they did, either the notes or the chord would be wrong...
Bear in mind this answer is only a starting point, covering basics. Get out and play with others - this will help your timing and how to play as part of a team. You'll never get this experience sitting in your bedroom with backing tracks. If you make a mistake, you can re-start them. Not so easy with live musicians...
Answer: "My question is, what's the next step?" Your question is most profound - and very open ended. However the 'next step' may well be: add something else to your playing. Perhaps challenge yourself with something like giving due consideration to what the chords are. The notes you play are generally based around the scales and the chords are based on the scale notes. The simplest 'chords' to actually play are called power chords. They are played with 2 notes, usually the root note and the fifth note of the scale.  "I have learnt all positions of the pentatonic scale, know a handful of licks and have a basic knowledge of music theory".The pentatonic scale positions are useful but how do you join them together? This is just one example of a way to get something happening. Like the old saying "sometimes you just gotta' get out of the 'BOX'" Explore ways to connect the boxes. What are the common notes? I did some theory etc. at the Sydney Australia Confusitorium of Music. It's good to have some knowledge on scale and chord construction - as with Pentatonics and guitar playing in general it's nearly always about repeating patterns. Some go up - some go down - many in fact go across, while they are going up and down. Work out your octave notes in all keys across and along the fret board and then explore connecting the dots. When you have reached a plateau and feel flat - look for a mountain or a steep hill - challenge yourself again - it will energise you. Discipline is simply doing it , then do it again the next day, and the next. In the explanation of power chords sheet, I have misplaced the coloured bits - very sorry about that - the other charts will give you a visual idea any way.
Answer: Listen, Listen, Listen....oh, and Listen some more!!  Play along with some of your favorite artists.  I know at first you'll fumble quite a bit, but over time you will pick up more and more licks.
Also, try to actually transcribe some of the solos you like to listen to.  Then, play what you've transcribed.  Over time, you will see more and more patterns that the greats keep throwing in with different variations.
Another trick is to sing a solo, record your singing, and then transcribe that.  Over time you'll build up your own library of patterns and licks.
Bottom line...you sound like you have the basics behind the theory...it is time for the ear and brain to get some concert time together.
Good luck!
Answer: If you just play your guitar against chord changes without regard to the story you're trying to tell, your solos won't be very interesting.
Here's a path to making interesting solos.
First, learn to play chord tones in your solo chord progression.  Finger each chord in your backing track and just play the notes that are in each chord in your voicing (fingering).  If you know multiple voicings for a chord, even better.  Play all of those.
Second, learn to play the scale tones in your chord progression in the same positions as you play your chord voicings.  You say you know the pentatonic scales, that's fine for a start.  You'll want to learn the major and minor scales later but that can wait for now.
Next, play both the chord tones and the scale tones in your solo.  Concentrate on playing the chord tones and use the scale tones to connect them by either moving up or moving down and by moving in varied increments of a fret or more.
You want to concentrate on the chord tones because they are the strongest notes of the solo.  Once you get this down, try the trick of big jump up and small steps down and vice versa.  Another tasty trick is taking a fragment of what you're playing and repeating it.  Repeat and vary your ideas a lot, it helps glue your solo together.  You can find more tricks that also apply to other forms of music at https://www.cs.hmc.edu/~keller/jazz/improvisor/HowToImproviseJazz.pdf
Okay, now you have the basic techniques down for doing a solo.  Now you have to learn to tell a story.
A story follows a narrative arc. A narrative arc is usually:

Exposition: The introduction of the story in which characters are
introduced, setting is revealed.  Here is where you can introduce a melodic fragment, riff or themes that you want to play with and against.  A memorable Roy Buchanan solo only used a single note.
Rising Action: A series of events that complicate matters for the
protagonist, creating a rise in the story's suspense or tension.  In music, rising action can be increasing speed, volume, distortion, dissonance or two themes in a call and response.  There are others but this is a start.
Climax: The point of greatest tension in the story and the turning
point in the narrative arc from rising action to falling action.
Falling Action (Anti-climax): After the climax, the unfolding of
events in a story's plot and the release of tension leading toward
the resolution.
Resolution: The end of the story, typically, in which the problems of
the story and of the protagonists are resolved.

You can cut this arc at any point.  I'm rather fond of ending solos at the climax but YMMV.
The best way to learn to tell a story with your solos is to listen to lots of great solos and sing along with them.  What's a great solo?  A solo with a narrative arc.  Once you've got this down, go back to your backing track and sing solos until you feel like you can tell a story.  Once you can sing the solos, try to play your guitar like you're singing.  Your playing doesn't have to be an exact copy of your song.  What you want it is the feel.
That's what I got.  Go forth and make an impact.  Even with relatively limited technique your solos will stand out against most of the rest.
Answer: just play mate...i usually overdrive any backing track and hit notes all over the neck without knowing what they are - as long as they sound good - sometime i play the same note over and again - just do what makes you feel good - dont let anyone tell you otherwise either...some of the greatest musicians on the planet were told at once time or another "your no good"!!!
Answer: meh... just learn the maze... every note, scale and mode is implicit within it. Once you know the maze, changing key just shifts the maze up or down, and then just meander about the maze and the magic will come!
Comment: What actually constitutes 'the maze'?
Comment: Not a useful answer unless you can explain in more details what you mean.  Don't believe I have seen the term "maze" in any musical resources - but happy to be wrong,


P-Adic Expansion of Rational Number (Reverse Direction)

Question: So I checked Method of finding a p-adic expansion to a rational number
and also P-adic expansion of rational number
Many questions here is of the form: Given a rational number, find its p-adic expansion. The solution to this is long division or some sort of geometric series argument.
What if I want to go backwards. i.e., given the p-adic expansion, what is the rational number assosciated to it? (Of course, not every p-adic expansion is rational so from reading texts, it seems the p-adic expansion of rational numbers eventually repeat so lets assume the ones we work with do)
To make this a concrete question, lets say I have like
$5^{-1} + 1 + 2*5 + 5^2 + (4*5^3 + 2*5^4 + 3*5^5 + 2*5^7 + 5^8) + (4*5^9 + 2*5^{10} + 3*5^{11} + 2*5^{13} + 5^{14}) + (4*5^{15} + 2*5^{16} + 3*5^{17} + 2*5^{19} + 5^{20})+...$
where I put the repeated parts in parenthesis. So if the first term is $5^{-1}$, lets say it is .1121(423021 repeat). How would I find the rational number associated to it?
Answer: I would write:
$$ x = {\ldots}\overline{120324}121.1_5 $$
and then add/subtract the appropriate finite base-5 fraction to make it a pure repeating number ending at the ones:
$$x-1.1_5 = {\ldots}\overline{120324}120_5
= {\ldots}\overline{324120}_5 $$
Then the I can convert that to a fraction essentially like one does for an ordinary decimal fraction, except that the analogue of $0.999{\ldots}_{10}=1$ is now ${\ldots}444_5=-1$:
$$ \begin{align}
x - \tfrac65 &= 324120_5 \cdot {\ldots}\overline{000001}_5
= \frac{324120_5}{444444_5} \cdot {\ldots}\overline{444444}_5
= -\frac{324120_5}{444444_5}  \\
\implies\quad
x &= \frac{6}{5} - \frac{324120_5}{444444_5}
= \frac65 - \frac{11160}{15624} = \frac{37944}{78120} =\frac{17}{35}
 \end{align} $$

Alternatively you could start with
$$ \frac{x - 121.1_5}{5^3} = {\ldots}\overline{120324}_5$$
and convert the right-hand side of that to a fraction in the same way.
Comment: Great thanks. So the idea is make the repeat at starting at the ones, multiply and divide by -1, and then convert to fractions using the 4444 repeat.
Answer: Hint: The "repeating part" is a geometric series.


Parse JSON data with objective-C

Question: I am trying to practice parsing jSON data using the youTube most popular feed and use the values to plug into a tableview.
Here is my code to GET:
NSURL *url = [NSURL URLWithString:@"http://gdata.youtube.com/feeds/api/standardfeeds/most_popular?v=2&alt=json"];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setTimeoutInterval:15.0];

_jsonArray = [[NSMutableArray alloc]init];

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

    if (connectionError == NULL)
    {
        NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&connectionError];

        NSDictionary *firstlayer = [responseDictionary objectForKey:@"feed"];

        NSDictionary *secondLayer = [firstlayer objectForKey:@"entry"];

        _jsonArray = [secondLayer valueForKey:@"title"];

        NSLog(@"%@",_jsonArray);

        [self.tableView reloadData];

    }else{
        NSLog(@"Connection failed, please try again later");
    }
}];

Here is the response:
2015-02-12 11:37:44.679 RestDemo[27043:2384786] (
        {
        "$t" = "Steven Yeun & Conan Visit A Korean Spa  - CONAN on TBS";
    },
        {
        "$t" = "Woman in minivan stops high speed chase in Dallas - 2/11/15";
    },
        {
        "$t" = "Anything Can Be Sexy with Dakota Johnson";
    },
        {
        "$t" = "Pitch Perfect 2 \U2013 Official Trailer 2 (HD)";
    },
        {
        "$t" = "Bill Belichick Talks About Deflategate with David Letterman";
    },
        {
        "$t" = "\"Trainwreck\" Official Red Band Trailer";
    },
        {
        "$t" = "TRAINWRECK Trailer #1 (2015) Judd Apatow Comedy Movie HD";
    },
        {
        "$t" = "HEAT MAP Microwave- a NEW invention";
    },
        {
        "$t" = "The Transgender Fight For Safe Bathrooms";
    },
        {
        "$t" = "This Is SportsCenter - Sharks";
    },
        {
        "$t" = "23 Weird Awards - mental_floss on YouTube - List Show (246)";
    },
        {
        "$t" = "Honest Trailers - Boyhood";
    },
        {
        "$t" = "Dr. Phil on Punishment Haircuts";
    },
        {
        "$t" = "Calvin Harris - Pray to God ft. HAIM";
    },
        {
        "$t" = "Understanding Boko Haram";
    },
        {
        "$t" = "Guys Read Each Other\U2019s Texts To Their Girlfriends | Elite Daily";
    },
        {
        "$t" = "Here\U2019s the first behind the scenes footage of SPECTRE.";
    },
        {
        "$t" = "STAR WARS - CROSSGUARD LIGHTSABER";
    },
        {
        "$t" = "Florence + The Machine - How Big How Blue How Beautiful";
    },
        {
        "$t" = "DSCOVR Launches Aboard SpaceX Falcon 9";
    },
        {
        "$t" = "Sergei Polunin, \"Take Me to Church\" by Hozier, Directed by David LaChapelle";
    },
        {
        "$t" = "What Are Measles Parties?";
    },
        {
        "$t" = "Sevyn Streeter - Don't Kill The Fun ft. Chris Brown [Official Video]";
    },
        {
        "$t" = "Sia - Chandelier (57th GRAMMYs feat. Kristen Wiig & Maddie Ziegler)";
    },
        {
        "$t" = "50 Shades of Buscemi (Trailer Recut)";
    }
)

How can I unwrap it from this array to assign them into a tableview.
Comment: You can "assign" that array to a tableView right now -- there's no restriction on what you can use for a dataSource.
Answer: Ups, I will edit:
To show your JSON array in a table view you have to use UITableView delegate and data source.
 self.tableView.delegate = self;
 self.tableView.dataSource = self;

And then implement tableview data sources and delegates:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   return _jsonArray.count;
}
-(UITableViewCell *) tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath {

   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"];
   if (cell == nil) {
   cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"myCell"] autorelease];
   cell.textLabel.text = [_jsonArray objectAtIndex:row];
   return cell;
}

Comment: Read the question again. The output shown in the question is the `_jsonArray`. Besides, the question isn't about parsing the JSON. It's an overly broad question about getting the obtained array of data into a table view.

Parse JSON data with objective-C


Mandrill sends repeated emails with django mailsnake

Question: I have a function that runs every hour with apscheduler, this verifies few conditions and according to this sends an email to an arrangement of emails
from mailsnake import MailSnake
mapi = MailSnake('XXXXXXXX', api='mandrill')
def functionEverHour():
     users=Users.objects.all()
     for users in users:
         if users.notificated==False:
             mapi.messages.send(message={'html':'sending emails', 'subject':'test', 'from_email':'firstname.lastname@example.com', 'from_name':'example', 'to':[{'email':str(users.email)}]})

maybe putting this line (mapi = MailSnake('Xajnas12sjnjas', api='mandrill')) in the cycle avoid that kind of mistake?
what does exactly mapi = MailSnake ('Xajnas12sjnjas' api = 'mandrill') that opens a connection to mandrill and never closes and that's the reason I sent emails repetitive (is accumulative?)?
Thanks
Answer: This may or not be an error, but why are you doing users in users? It's probably not going to cause an error, but the naming isn't the best in my opinion. My suggestion would be to use naming: all_users = User.objects.all() and users_to_notify in all_users:
Not sure why you're using MailSnake, but this is something mandrill's API handles pretty well.
this is my suggestion about how to change your code. One thing is your method is doing too much. It's handling both the logic of finding the users to notify as well as send the emails. It's best practice to have a function and objects, etc handling only one responsibility.
def get_users_to_notify():
    all_users=Users.objects.all()
    users_to_notify = []
    for user in all_users:
        if user.notified==False:
            users_to_notify.append(user)
    return users_to_notify

def functionEverHour():
    users = get_users_to_notify()
    for user in user:
        mapi.messages.send(message={'html':'sending emails', 'subject':'test', 'from_email':'email@example.com', 'from_name':'example', 'to':[{'email':str(users.email)}]})


How to copy part of an array to another array in C#?

Question: How can I copy a part of an array to another array?
Consider I'm having
int[] a = {1,2,3,4,5};

Now if I give the start index and end index of the array a it should get copied to another array.
Like if I give start index as 1 and end index as 3, the elements 2, 3, 4 should get copied in the new array.
Answer: int[] b = new int[3];
Array.Copy(a, 1, b, 0, 3);

a = source array
1 = start index in source array
b = destination array
0 = start index in destination array
3 = elements to copy
Comment: @Hamish well, maybe. Personally I wouldn't add explicit names unless it made the code significantly clearer, and I'm not sure (in this case) that the parameter names *by themselves* would achieve that.
Comment: With named parameters that are available now, you would not need to document any of the 5 parameters.
Answer: See this question. LINQ Take() and Skip() are the most popular answers, as well as Array.CopyTo().
A purportedly faster extension method is described here.
Comment: Note that LINQ is not ideal when dealing with performance-critical situations
Comment: Another question on SO with a suitable answer: http://stackoverflow.com/a/3539065/411428
Comment: Array.CopyTo copies all elements and the original question is "How to copy A PART of an array?". Also: when already working with an array, Skip() Take() isn't the best option from a performance perspective.
Answer: int[] a = {1,2,3,4,5};

int [] b= new int[a.length]; //New Array and the size of a which is 4

Array.Copy(a,b,a.length);

Where Array is class having method Copy, which copies the element of a array to b array.
While copying from one array to another array, you have to provide same data type to another array of which you are copying.
Answer: In C# 8+ you can use ranges.
int a[] = {1,2,3,4,5};
int b[] = a[1..4]; // b = [2,3,4];

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-8.0/ranges
Answer: Note: I found this question looking for one of the steps in the answer to how to resize an existing array.
So I thought I would add that information here, in case anyone else was searching for how to do a ranged copy as a partial answer to the question of resizing an array.
For anyone else finding this question looking for the same thing I was, it is very simple:
Array.Resize<T>(ref arrayVariable, newSize);

where T is the type, i.e. where arrayVariable is declared:
T[] arrayVariable;

That method handles null checks, as well as newSize==oldSize having no effect, and of course silently handles the case where one of the arrays is longer than the other.
See the MSDN article for more.
Answer: In case if you want to implement your own Array.Copy method.
Static method which is of generic type.
 static void MyCopy<T>(T[] sourceArray, long sourceIndex, T[] destinationArray, long destinationIndex, long copyNoOfElements)
 {
  long totaltraversal = sourceIndex + copyNoOfElements;
  long sourceArrayLength = sourceArray.Length;

  //to check all array's length and its indices properties before copying
  CheckBoundaries(sourceArray, sourceIndex, destinationArray, copyNoOfElements, sourceArrayLength);
   for (long i = sourceIndex; i < totaltraversal; i++)
     {
      destinationArray[destinationIndex++] = sourceArray[i];
     }
  }

Boundary method implementation.
private static void CheckBoundaries<T>(T[] sourceArray, long sourceIndex, T[] destinationArray, long copyNoOfElements, long sourceArrayLength)
        {
            if (sourceIndex >= sourceArray.Length)
            {
                throw new IndexOutOfRangeException();
            }
            if (copyNoOfElements > sourceArrayLength)
            {
                throw new IndexOutOfRangeException();
            }
            if (destinationArray.Length < copyNoOfElements)
            {
                throw new IndexOutOfRangeException();
            }
        }


OLS - Non stationary variables but stationary residuals - is this OK or not?

Question: I am running an OLS on which the dependent variable (Y) and the independent variables (X1, X2, X3, ...) are non-stationary. But the residuals are found to be stationary. Does this mean my regression is OK? Or is it spurious? I tried searching online but I got a bit confused.
Comment: Do all of your variables have unit roots? Or what kind of nonstationarity is it?
Comment: Your point estimates are kind of OK, but probably not the standard errors, confidence intervals, p-values, etc. You would be safer to use an error correction model (ECM; see [tag:ecm]) $$\Delta y_t=\gamma_0 + \alpha \text{ect}_{t-1}+\gamma_1 \Delta x_{1,t}+\dots+\gamma_p \Delta x_{p,t}$$ where $\text{ect}$ is the error-correction term (a stationary linear combination of $y$ and $x$s).
Comment: See [these references](https://stats.stackexchange.com/questions/20514/books-for-self-studying-time-series-analysis), also Lütkepohl ["New Introduction to Multiple Time Series Analysis"](https://www.springer.com/gp/book/9783540401728) (2005).
Comment: The variables can be non-stationary provided their relation doesn't change over time (if it does and you don't model it, you will see this in the residuals, they will not be stationary). A simple example of your case where OLS is fine would be $Y_t = \beta t + u_t$ with $u_t$ stationary. If you look into "co-integration" you can find the relevant time series theory.
Comment: @RichardHardy yes they have unit root but the residuals are stationary. Is that ok or problematic?
Comment: @RichardHardy do you have some reference (book, paper, online article) that states and justifies why the point estimates are ok in case the variables are non-stationary but the residuals are stationary?
Comment: Most time series textbooks include a treatment of regression of cointegrated variables. *Superconsistency* is one keyword to look for (characterizing the point estimator in such a regression).
Comment: @RichardHardy thank you. Can you please recommend some good books so that I order them and read them?
Comment: Many thanks Richard!
Answer:
...the dependent variable (Y) and the independent variables (X1, X2,
X3, ...) are non-stationary. But the residuals are found to be
stationary. Does this mean my regression is OK?...

This suggests there is a cointegrating relationship among the dependent and independent variable.
In this case, the OLS estimates are (super)-consistent.
For example, consider the simplest cointegration model:
$$
y_t = \beta x_t + \epsilon_t
$$
where $\epsilon_t \stackrel{i.i.d.}{\sim} (0,1)$ and $u_t \stackrel{i.i.d.}{\sim} (0,1)$ are two independent white noise and
$$
x_t = \sum_{s = 0}^t u_s
$$ is a random walk with $\{ u_t \}$ as innovations.
Both $x_t$ and $y_t$ are not non-stationary but the population error term $y_t - \beta x_t$ is stationary. There is a cointegrating relationship with cointegrating vector $(1, -\beta)$.
The OLS estimate $\hat{\beta}$ satisfies
$$
T ( \hat{\beta} - \beta ) = \frac{\sum_1^T x_t \epsilon_t}{\sum_1^T x_t^2}
\stackrel{d}{\rightarrow} \frac{\int_0^1 W^{(1)}_t dW^{(2)}_t}{\int_0^1 \left( W^{(1)}_t \right)^2 dt},
$$
where $W^{(1)}$ and $W^{(2)}$ are independent standard Brownian motions.
Therefore $\hat{\beta} - \beta = O_p(\frac{1}{T})$, i.e. $\hat{\beta}$ is T-consistent. In contrast, in the stationary case, $\hat{\beta}$ is $\sqrt{T}$-consistent.
Here (T-)consistency holds even when $\epsilon_t$ and $u_t$ are correlated.
This is in contrast to the stationary case where consistency requires $E[\epsilon_t x_t] = 0$.
Unlike the stationary case, where inference is obtained via asymptotic normal distributions, here the asymptotic distribution of $T ( \hat{\beta} - \beta )$ is non-normal. Same goes for the asymptotic distribution of the usual Wald/F-statistics (critical values can be obtained by simulation, if needed).
Notice that sum of squared residuals of this cointegration regression is
$$
\sum_1^T \epsilon_t ^2 - \frac{( \sum_1^T x_t \epsilon_t)^2}{\sum_1^T x_t^2} = O_p(T) - O_p(1) = O_p(T),
$$
which implies the residuals are stationary.
On the other hand, if the regression is spurious, the sum of squared residuals is
$$
\sum_1^T y_t ^2 - \frac{( \sum_1^T x_t y_t)^2}{\sum_1^T x_t^2} = O_p(T^2) - O_p(T^2) = O_p(T^2)
$$
which implies the residuals are non-stationary.
The fact that you found residuals to be stationary
suggests your regression is cointegrated, rather than spurious.
Further Comments

In applying unit root tests to residuals to check for non-stationarity, standard critical values cannot be used. For example, for the Augmented Dickey-Fuller test-statistic computed using residuals, the Engel-Granger critical values should be used.

As already pointed out in comments, for a cointegration model there exists a corresponding error correction model (ECM). For the above simple example, the corresponding ECM is
$$
\Delta y_t = \Delta x_t + \underbrace{ (y_{t-1} - \beta x_{t-1})}_\text{$\epsilon_t$}.
$$
While the cointegration model describe the long-run equilibrium relationship between $x_t$ and $y_t$, the corresponding ECM describes the short-run relationship between $\Delta y_t$, $\Delta x_t$, and the deviation $\epsilon_t$ from long-run level. Notice that all variables in the ECM are stationary. Which model you estimate depends on the question of interest. To estimate the ECM, regress $\Delta y_t$ on $\Delta x_t$ and $e_t$ where $e_t$ is the residual from the cointegration regression.


VS2008 Prefers GAC reference to Assemblies in Solution Folder

Question: I am using some 3rd party libraries in my solution and have saved these in a separate source-controlled folder called 3rdParty. I have added references to the DLLs in this folder from the VS2008 IDE. However, I find that after saving, closing and opening the solution, the references have been changed to point to the assemblies in the GAC.
The reason for using the 3rdParty folder is that I can easily get latest version from any machine and build my project without having to install anything in the GAC folder. How can I get VS2008 to leave my references untouched?
Edit: After seeing Benjol's answer, I have been wondering if I could use an assembly manifest to fix this. Will this help solve my problem?
Comment: Are you sure, the change is maid by VS? We are using same scenario, and we havent problem with it. The only case, when is references changed to GAC assemblies is when the 3rd party component need additional assemblies.
Comment: Yes. I verified that the change is made by VS on save.
Answer: There's a "CopyLocal" setting for references, if you set this to true and set the SpecificVersion setting to false then it should use the local references rather than the GAC ones.
GAC dlls are referenced before local ones because they are designed to be shared, but should only be selected if there is a specific version specified.
Would it be possible for you to remove these assemblies from the GAC if they continue to cause problems?
Comment: mat1t, my assemblies are in a folder located at ..\..\3rdParty so I don't think CopyLocal will be able to figure out the folder name automatically.

The DLLs in questions are available in the GAC for some of the developers since they are using applications which need the GAC references. Deleting the GAC assemblies works but causes problems for folks who need the GAC reference as well.
Answer: Even if you could get VS to look in your local folder, that would be no help at runtime (I mean F5/debug runtime), because .Net will look in the GAC first anyway.
And with reference to CopyLocal, AFAIK, that just tells the compiler to copy a version of your referenced DLL into the /bin folder of your project, so there shouldn't be any issues with 'complicated' paths.
Comment: Is there any way to force the framework to look in the same directory as the application? Can't manifest files be used to do this?
Comment: Short answer, sorry I don't know. Long answer: try looking through this lot: http://stackoverflow.com/search?q=gac+force+local
Answer: In order for it to pick up your local assembly you have to go into the project properties, under the Reference Paths tab and add the local directory (3rd party in your case) to the list of directories. This should address your problem.
Answer: We use a similar approach here where I work, although we call the folder ReferencedDLLs, and we didn't have any problems with it so far.
One thing you can try, though, is to edit the project file to remove the PathHint for the references in question, this way the VS2008 doesn't know where to look and it will start the normal approach.
Comment: Paulo, how do remove the PathHint? I couldn't locate this in the UI.
Comment: I't not on the UI. You need to unload the project and edit the project file manually.
Comment: I just checked and there were no HintPath or PathHint attributes in the project file. I guess it's different for C++/CLI projects.
Comment: Also, I believe that what I'm trying to do works only if the assemblies in question are not already in the GAC.


Node/JavaScript function to return a new path, given a filepath, basepath and new destpath

Question: What custom function can be used (in node) whereby if passed three arguments, namely filePath, basePath and destPath it returns a new path. For example.
Example function signature
var path = require('path'); // Nodes `path` module is likely to help?

/**
 * Returns a new filepath
 * @param {String} filePath - The path to the source file.
 * @param {String} basePath - The path to determine which part of the
 *     FilePath argument is to be appended to the destPath argument.
 * @param {String} destPath - The destination file path.
 * @return {String} The new filepath.
 */
function foo(filePath, basePath, destPath) {

    // ... ?

    return newFilePath;
}

Example usage:
Below are some examples of invoking the function and the value I'd expect returned given the arguments passed:
// Example A

var a = foo('./foo/bar/baz/quux/filename.json', 'foo/bar/baz/', './dist');

console.log(a) // --> 'dist/baz/quux/filename.json'

// Example B

var b = foo('./a/b/c/d/e/filename.png', './a/b/c', './images/logos/');

console.log(b) // --> 'images/logos/c/d/e/filename.png'

// Example C

var c = foo('images/a/b/filename.png', './images/a/b', 'pictures/');

console.log(c) // --> 'pictures/b/filename.png'

Further info

As you can see from the example function invocations the basePath String will inform the function where the filePath value should be trimmed, and its purpose is akin to the gulp base option used with thegulp.src() function.
The argument String values (i.e. paths) will always be relative, however, they will sometimes include the current directory prefix ./ and sometimes not. The trailing forward slash / may or may not be present on the path String.
The solution must work cross platform without any additional dependencies. It also must be usable with early node versions ( >= 0.10.28 )
I've had various failed attempts using the utilities of the path module, such path.normalize then splitting the Array etc, etc. However, I'm quite certain the path module will be utilized in the solution.

Thanks in advance.
Answer: You could achieve this using simple string replacement. Just normalize the paths before this.

filePath and basePath: if they start with ./, remove it.
basePath : if it ends with / remove it, then remove the last path part (baz in your first example)
filePath.replace(basePath, destPath)
Answer:

function foo(filePath, basePath, destPath) {
    if(filePath.charAt(0)=='.'){
      filePath=filePath.substr(1,filePath.length);
    }
    if(filePath.charAt(0)=='/'){
      filePath=filePath.substr(1,filePath.length);
    }
    if(basePath.charAt(0)=='.'){
      basePath=basePath.substr(1,basePath.length);
    }
    if(basePath.charAt(0)=='/'){
      basePath=basePath.substr(1,basePath.length);
    }
    if(destPath.charAt(0)=='.'){
      destPath=destPath.substr(1,destPath.length);
    }
    if(destPath.charAt(0)=='/'){
      destPath=destPath.substr(1,destPath.length);
    }
    if(basePath.charAt(basePath.length-1)!='/'){
      basePath+="\/";
    }
    if(destPath.charAt(destPath.length-1)!='/'){
      destPath+="\/";
    }
    var temp = basePath.split('/')[basePath.split('/').length-2];
    var newFilePath = temp+'/'+filePath.split(basePath)[1];
    newFilePath=destPath+'/'+newFilePath;
    return newFilePath.replace(/\/\//g,"/");
}
// Example A

var a = foo('./foo/bar/baz/quux/filename.json', 'foo/bar/baz/', './dist');

console.log(a) // --> 'dist/baz/quux/filename.json'

// Example B

var b = foo('./a/b/c/d/e/filename.png', './a/b/c', './images/logos/');

console.log(b) // --> 'images/logos/c/d/e/filename.png'

// Example C

var c = foo('images/a/b/filename.png', './images/a/b', 'pictures/');

console.log(c) // --> 'pictures/b/filename.png'
Comment: Thanks for looking at this, however, examples B and C resulted in double forward slashed.  a = `./images/logos//b//d/e/filename.png` and
c =  `pictures//a//filename.png`.
Comment: Which arguments would these be? Can you show me their function calls so I could reproduce (and hopefully fix) the error?
Comment: Apologies my previous comment says **a =** and it should say **b =** Simply invoke your function in node using examples B and C, (as defined in my OP), and you should see the double forward slashes in the resultant log.
Comment: Oh, I see what you're saying-- the filepaths given shoiuld be the results of running the examples they're paired to. Well, I fixed both the double-slash issue and an issue that happened if arguments 2 or 3 didn't have an ending slash.


Wrong WSUS WUA server assigned to DMZ agents

Question: Having a problem with the WSUS part of SCCM 2012 not working on agents in our DMZ.
These agents have PKI certificates from internal PKI, and are appearing in the console as active inventory.
Because many parts of the SCCM roles must be configured for HTTP or HTTPS and not both at the same time:
1 - these agents are on a boundary that assign them to a MP that is configured for SSL. Agent control panel shows correct MP.
2 - these agents are also in a collection with different client settings to assign them an 8531 appcat.
SDCSCMP23 is the HTTP WSUS/Appcat/MP for internal agents
SDCSCMP25 is the SSL WSUS/Appcat/MP with PKI certs for DMZ agents
The problem is that SCCM is configuring these agents to use the HTTP parts of the Infrastructure for WSUS, and not the HTTPS parts. Per MS Doc, Client Settings are supposed to auto assign an HTTPS appcat before an HTTP one, but this was not happening, so I made my own client settings to assign the HTTPS appcat.
Simply modifying the firewall config to permit 443, 8531 to this other server is NOT an option, because those servers are listening on 80, 8530 (for internal HTTP agents) not 443, 8531. We have a requirement to use only 443, 8531 for the DMZ agents. Have verified that 443, 8531 are open through the firewall to SDCSCMP25 from the agents. This is SCCM 2012 SP1. We are NOT assigning WSUS servers through GPO.
How do I get SCCM to assign the correct WSUS servers to these agents?
<code>WUAHandler.log
Enabling WUA Managed server policy to use server: HTTP://SDCSCMP23.ACME.COM:8530
m_spSearchJobUpdateSearcher->EndSearch(m_spSearchJob, &spSearchResult), HRESULT=80072ee2 (e:\nts_sccm_release\sms\client\updatesmgmt\wuahandler\cwuahandler.cpp,3064)   WUAHandler  4/11/2013 6:09:59 PM    1480 (0x05C8)
OnSearchComplete - Failed to end search job. Error = 0x80072ee2.    WUAHandler  4/11/2013 6:09:59 PM    1480 (0x05C8)
Scan failed with error = 0x80072ee2.    WUAHandler  4/11/2013 6:09:59 PM    1480 (0x05C8)

WindowsUpdate.log
2013-04-11  18:09:05:376     828    15fc    Agent   ***********  Agent: Refreshing global settings cache  ***********
2013-04-11  18:09:05:376     828    15fc    Agent     * WSUS server: HTTP://SDCSCMP23.ACME.COM:8530 (Changed)
2013-04-11  18:09:05:376     828    15fc    Agent     * WSUS status server: HTTP://SDCSCMP23.ACME.COM:8530 (Changed)
2013-04-11  18:09:35:641     828    1668    PT  +++++++++++  PT: Synchronizing server updates  +++++++++++
2013-04-11  18:09:35:641     828    1668    PT    + ServiceId = {3DA21691-E39D-4DA6-8A4B-B43877BCB1B7}, Server URL = HTTP://SDCSCMP23.ACME.COM:8530/ClientWebService/client.asmx
2013-04-11  18:09:59:235     828    1668    Misc    WARNING: Send failed with hr = 80072ee2.
2013-04-11  18:09:59:235     828    1668    Misc    WARNING: SendRequest failed with hr = 80072ee2. Proxy List used: <(null)> Bypass List used : <(null)> Auth Schemes used : <>
2013-04-11  18:09:59:235     828    1668    PT    + Last proxy send request failed with hr = 0x80072EE2, HTTP status code = 0
2013-04-11  18:09:59:235     828    1668    PT    + Caller provided credentials = No
2013-04-11  18:09:59:235     828    1668    PT    + Impersonate flags = 0
2013-04-11  18:09:59:235     828    1668    PT    + Possible authorization schemes used =
2013-04-11  18:09:59:235     828    1668    PT  WARNING: GetConfig failure, error = 0x80072EE2, soap client error = 5, soap error code = 0, HTTP status code = 200
2013-04-11  18:09:59:235     828    1668    PT  WARNING: PTError: 0x80072ee2
2013-04-11  18:09:59:235     828    1668    PT  WARNING: GetConfig_WithRecovery failed: 0x80072ee2
2013-04-11  18:09:59:235     828    1668    PT  WARNING: RefreshConfig failed: 0x80072ee2
2013-04-11  18:09:59:235     828    1668    PT  WARNING: RefreshPTState failed: 0x80072ee2
2013-04-11  18:09:59:235     828    1668    PT  WARNING: Sync of Updates: 0x80072ee2
2013-04-11  18:09:59:235     828    1668    PT  WARNING: SyncServerUpdatesInternal failed: 0x80072ee2
2013-04-11  18:09:59:235     828    1668    Agent     * WARNING: Failed to synchronize, error = 0x80072EE2
2013-04-11  18:09:59:235     828    1668    Agent     * WARNING: Exit code = 0x80072EE2
</code>
Answer: It seems to me that the core issue here is the attempt to configure multiple SUPs (one SSL, one not) within the site. You can only have one Software Update Point (SUP) per site, and the SUP is either SSL-enabled, or not.
I see only have two possible options:

Enable the SUP for SSL and require SSL for ALL clients.
Install a secondary site in your DMZ with its own SUP.
Comment: Support for multiple SUPs was added in SP1


Classifying a dataset using Naive Bayes

Question: I am trying to classify a dataset of tweets using the Naive Bayes classifier found in the NLTK. However, rather than classifying a single sentence, such as below
classifier.classify(toDict("this is good"))

I need to have something like this, below.
classifier.classify(toDict(tweets))

My issue is that rather than classifying one sentence, I need to classify a full dataset. The commented code is what I have already tried.
Rest of my code is below.
import nltk
import numpy as np
import pandas as pd
import re
import random
from pandas import DataFrame
from nltk import *
from nltk import classify
from nltk import NaiveBayesClassifier
from nltk import FreqDist
from nltk.corpus import stopwords
from nltk.corpus import twitter_samples
from nltk.tokenize import word_tokenize
from nltk.tokenize import WhitespaceTokenizer as w_tokenizer
nltk.download('punkt')
nltk.download('stopwords')

def toDict(word):
     return {word : True}

posDataset = [(tweet_dict, "Positive")
                     for tweet_dict in posModel]

negDataset = [(tweet_dict, "Negative")
                     for tweet_dict in negModel]

trainingDataset = posDataset + negDataset

random.shuffle(trainingDataset)

trainData, testData = trainingDataset[8000:], trainingDataset[:6000]

classifier = NaiveBayesClassifier.train(trainData)

#print(classifier.classify(dict((item, True) for item in tweets)))
#classifier.classify()

classifier.classify(toDict("this is good"))

'tweets' is a pandas Series, items stored as lists. Image example is here
Here is the error message I get from running the commented out code.
TypeError                                 Traceback (most recent call last)
<ipython-input-28-957eed734b8a> in <module>
     20 classifier.classify(toDict("this is good"))
     21
---> 22 print(classifier.classify(dict((item, True) for item in tweets)))
     23 #classifier.classify()

TypeError: unhashable type: 'list'

Comment: What *exactly* is your issue and your *question*?
Comment: I need to classify the tweets set, I thought it was obvious in first section of the post. Ill edit.
Comment: But what is your *issue*? What you have tried so far, and how it fails? Do you get errors? What are they?
Comment: My issue is that I cant run a full dataset through my classifier, I updated my post the first time you commented. I commented out the code at the bottom which I have tried. The error from the commented code is in the post, I have updated.
Comment: For the future, please keep in mind that "*I can't run it*" is not a valid issue description; a valid issue description includes 1) the full error trace 2) the *minimal* code necessary to reproduce it. See how to create a [mcve]. The fact that you did get an answer this time does not change the argument, I kindly suggest you follow the rules and guidelines to ensure meaningful responses.
Answer: The example below will give you a generic how-to.
Creating a test dataframe
>>> import pandas as pd

>>> df = pd.DataFrame({"text": ["this is a text", "that was a text", "but, you were a text"]})

>>> df
                   text
0        this is a text
1       that was a text
2  but, you were a text

Defining your classification function (example)
>>> def classify_by_size(x):
...     size = len(x)
...     if size < 15:
...         return "small"
...     elif size > 15:
...         return "big"
...     return "medium"
...

Note: The function above would be your classification method
Classifying
>>> df["new_column"] = df["text"].apply(classify_by_size)

>>> df
                   text new_column
0        this is a text      small
1       that was a text     medium
2  but, you were a text        big

So, in your case you would have something like:
def my_classification(x):
    return classifier.classify(toDict(x))

And the call:
df["new_column"] = df["text"].apply(my_classification)

This might work well for small dataframes.
Comment: Hi Paulo, thanks for your answer, would this still work with a Pandas Series type of data?
Comment: Yes, in the example above `df["text"]` is a data Series.

Classifying a dataset using Naive Bayes


Using two identifiers in uri

Question: I got a table that was partitionned on a datetime column.
If i let the get item of ApiPlateform, the query will check all partitions to found the item.
I'd like to be able to send also the date on the uri
<?php

#[ApiResource(
operations: [
new Get(uriTemplate: '/entities/{id}/{date}'),
)]
#[NeedLegacyConversion]
class Invoice
{
    protected ?string $id = null;
    protected ?\DateTime $date = null;
}

I'm a litle bit lost on it.
i try a lot of stuff (too many to remember) with uriVariables but nothing work.
I like the uri got 2 identifiers
Edit:
I was abble to use the datetime on uri using
ApiProperty:identifier on the both properties
define uriVariable on the Get for exemple
But there is a bug on APIP that can use datetime on identifier but crahs when it try to link an item and the identifiers to generete iris. It want a scalar value and fail to get a datetime :(
Answer: It's called composite key. I am not sure if API-Platform finally supports that. You can try by adding the attribute on the properties that should be your composite key:
#[ApiProperty(identifier: true)]
protected ?string $id = null;

#[ApiProperty(identifier: true)]
protected ?\DateTime $date = null;

Your uriTemplate would already fit this configuration.
If APIP does not already support that, you could implement a Doctrine Query Extension that is able to work with composite keys.
If it is only about the IRI (and in your database you just have a single key) you want to look at implementing a custom IriConverterInterface to allow using the DateTime object in the IRI.
PS: In this case you don't need the above ApiProperty attributes.

Using two identifiers in uri


PostgreSQL User Permissions

Question: I'm trying make a transition from MySQL to PostgreSQL, but find the user accounts/permissions system to be quite different.
With mysql, all accounts are handled internally by mysql. With postgres is seems I need to make an account within the system, as well as within postgres.
Is there a guide somewhere as to how system user accounts relate to postgres user accounts? The postgres manual didn't seem to elaborate much on this.
Answer: You only need to create system users if you want to use local authentication.
For network connections, you use CREATE USER and GRANT much as you are used to in MySQL.
The main difference is that in unlike MySQL where the authentication and authorization parts are all inside of tables in the mysql database, part of the authentication rules for Postgres are in an external file pg_hba.conf).
To let user foo connect to database bar from 10.1.1.0/24, you want a line like this in that file:
host bar foo 10.1.1.0/24 md5

After editing pg_hba.conf, remember to run
pg_ctl reload

to reload the config.
When the user tries to connect, they will be required to provide a password (which you provided when you created the user).
Also remember that in PostgreSQL everything is a role.  A role that you define as 'WITH LOGIN' is a user while one that does not have this flag is more like a group.  For flexibility, I tend to create users with passwords and WITH LOGIN.  I then create roles without passwords and grant this role to the login users.  My grants are to the group-like role rather than to individual users.
In pg_hba.conf, use +role to match anyone who has the role assigned (instead of foo in the above example)
Comment: Is it bad security to add this line: "host all 127.0.0.1/32 trust" ?
Comment: Ye,s that's a very bad idea unless you trust everybody on your machine. Including potential attackers coming in through other systems.
Comment: Also, doing host 127.0.0.1/32 is inferior performance wise to local authentication.  Local connections use a UNIX domain socket.  When you use that, you get the ability to use another auth mechanism called ident (the OS can tell a program the name of the user at the other end of the pipe).  So for local connections, ident is safer than trust.  TCP/IP connections to localhost are slower and you can't do ident auth with them.
Answer: Note that if a postgresql account is configured to be able to use both ident and md5, then by default it will try to use ident.
You can force it to use username/password (ie md5), by adding the option --host=localhost to the end of the psql commandline or similar.
This forces the connection to go through sockets, which disables ident, and therefore forces the username/password authentication.

PostgreSQL User Permissions


VSS Snapshot Warning - File c:\windows\system32\mtxcip2.dll is not present on the snapshot

Question: Our backup server is a Server 2012 R2 machine running Backup Exec 2012. I receive the error while backing up a Server 2008 server which is running the Backup Exec Remote Agent, Symantec Protection Server (For Endpoint Protection Small Business) and Microsoft Exchange 2007. The error occurs consistently every backup. I've searched the error and Microsoft KB955078 says it's caused by software that wasn't uninstalled properly. To correct the issue:

Contact the vendor of the software that originally installed the DLL file.
Re-install the software.

Unfortunately, I have no idea what software created this file. Further research into this issue has taught me that there is a registry key pointing a a non-existent file. If I remove said registry entry, the problem will go away.
In addition to running just the registry portion of ccleaner to look for bad keys, I've also manually searched the registry for the file. I could not find it on either. I also searched C:\ recursively for the file - no results. (Note: I don't usually run ccleaner on a server nor was I going to remove anything else besides this one specific key if it found it.)
I've completely exhausted all ideas on this. All machines are 100% up to date with both Windows and Symantec updates. Looking for help. Thank you in advance.
Answer: It looks like this is part of a device driver for a Matrox graphic card. Assuming that the serer is using that brand of graphic card, you could try uninstalling the driver completely (reverting to VGA) and installing it again.
Comment: It appears that was the old graphics driver before the server was virtualized with VMware. It now has VMware's 3D SVGA driver installed. I assume that a proper uninstall of the old video card never took place. Also, nothing useful in Add/Remove Programs.
Comment: Ah: P2V... It usually causes you to lose more time in the long run than it saves you in the first place.
Comment: Migrating Exchange wasn't an option and time was limited


Commerce Kickstart change full text search product display to https

Question: I am currently developing a drupal commerce site with commerce kickstart. I've set the site up so that it's mixed mode SSL using securepages, all seems to be working fine. However, I've found a bug with the full text search (used in the main products display view) which could potentially put customers off as they may think the site is unsecure. Plus the certificate does not show the EV SSL Green bar / padlock, it display's with a yellow warning.
All browsers apart from chrome work ok and from doing my research it looks like it's only the full text search which is causing the issue (when testing using chrome by pressing ctrl + shift + j it shows the error code) on line 223:
Mixed Content: The page at 'https://www.whiterabbitengland.us/contact-us' was loaded over a secure connection, but contains a form which targets an insecure endpoint 'http://www.whiterabbitengland.us/products'. This endpoint should be made available over a secure connection.
Has anyone else encountered this issue and found a way to set the full text search over https?
Thanks
Max
Answer: Maintainer of Commerce Kickstart.
I just checked out the site, and it's using a relative path like Drupal forms are expected to do. From your source:
<code><form action="/products" method="get" id="views-exposed-form-display-products-page" accept-charset="UTF-8">
</code>
The search form is a Views exposed filter exposed as a block. There isn't much trickery going on with the form beyond typical site building.
Also, I did not get mixed content warnings.
Comment: Hi Matt, I found a work around which I will have to do as couldn't find any other way to fix my issue. I've added the /products page into secure modules config so that each time products page is called it redirects to https. If I left it out of the securepages config chrome thought that the page was unsecure due to the search form would have searched via http.
Comment: Thats quirky! I think it'd be a good thing to open a corresponding ticket in either Secure Pages or Search API queue (since box is from Search API module.)


Como integrar uma tabela do banco de dados a outra?

Question: Exemplo: Um sistema que registra clientes, compras e produtos, cada um em uma tabela diferente. Tendo um registro de compras que deve possuir os campos:

Cliente: indica qual cliente já cadastrado (em outra tabela do banco) que efetuou a compra.
Produtos: seleciona qual foi o produto (que também está em outra tabela) que foi vendido para o cliente.

Além disso devo colocar outros campos como data de venda etc, mas isso não vem ao caso, pois quero saber como faço essa integração entre tabelas? Pegar o registro de outra tabela e associar a um campo de um registro de outra tabela. Já tentei pesquisar sobre isso mas não consegui encontrar, se me derem um exemplo de como funcionaria ou termos que devo pesquisar eu agradeceria.
Peço que não ponham muito código em linguagem do banco de dados, pois não entendo nada disso, os bancos que crio são totalmente visuais, ou seja, criados automaticamente pelo Visual Studio.
Detalhes: Deveria funcionar da seguinte maneira, ao querer registrar uma compra, o usuário informaria a data da venda (essa parte eu sei como faz), o cliente que comprou aquilo (esse cliente tem um registro em outra tabela então deve-se buscar e associar o nome do cliente ao seus dados armazenados na outra tabela) e por fim o produto vendido (que também possui registro em outra tabela)
Answer: A integração entre tabelas normalmente é feita por chaves estrangeiras. Uma chave estrangeira relaciona uma chave primária de uma tabela com a chave primária de outra tabela. Isto garante a integridade referencial entre tabelas.
Para o seu exemplo, uma compra deve relacionar produtos com um cliente. O ideal seria haver uma tabela associativa entre produtos e uma compra, tendo um campo adicional, o de quantidade. Ou seja, esta tabela associativa deve ter, além de sua chave primária, duas chaves estrangeiras, sendo uma apontando para uma compra e outra apontando para o produto que pertence a uma compra.
Comment: Valeu, deu pra entender um pouco e saber o que devo pesquisar agora pra fazer isso. No meu caso seria a tabela compra com duas chaves estrangeiras, uma apontando para cliente e outra para produto (a quantidade não é tão necessária na tabela compra, quando um elemento de produto for atribuído na tabela compra eu coloco pra diminuir uma quantidade daquele produto na tabela produto). Então devo transformar o campo Nome na tabela cliente e produto como chave primária né? Meio complicado isso hein kk vou dar uma pesquisada no youtube
Comment: Bom, eu fiz aqui no Visual Studio, mas não consegui distinguir de uma tabela normal, o campo Cliente aceitou um nome que não tinha na minha tabela cliente, o mesmo aconteceu com o produto..
Comment: O campo `Nome` não é uma boa alternativa como chave primária por ser um `varchar`, possivelmente. Chaves primárias e estrangeiras não podem ser fáceis de serem modificadas. Por mais que você diga que não vai ser modificado, há também o problema de `varchar` ser mais caro em custo de operação do banco de dados, para conferir valor, selecionar, inserir, atualizar... Sugiro fazer outra pergunta com a nova dúvida.


How to free member (i.e BSTR, SAFEARRAY, VARIANT) of an IDL User Defined Structure which is encapsulated in a VARIANT?

Question: I have a structure defined in IDL. This structure has following members:

{
    BSTR m_sFirst;
    BSTR m_sSecond;
    VARIANT m_vChildStruct; //This member encapsulate a sub structure
    SAFEARRAY __RPC_FAR * m_saArray;
}CustomINFO;

I am allocating the memory for the structs using CoTaskMemAlloc and encapsulating it in Variant as follows:

vV->vt = VT_RECORD;
vV->pvRecord = pStruct; //Pointer of sturct
vV->pRecInfo = pRI; //RecordInfo Interface

Is it enough to call VariantClear to deallocate the memory of struct and its members?
Will it also release the IRecordInfo interface?
Or i have to manually get the encapsulated struct and deallocate each member myself and then use CoTaskMemFree to deallocate sturct.
Thanks
Picaro De Vosio
Comment: You already need an IRecordInfo for the "main" structure.  Why not just declare the child structure as-is instead of using a variant?
Answer: VariantClear will call IRecordInfo::Clear, which releases the memory held by members of the struct, but supposedly doesn't release the struct itself (that's why you can't correctly return a struct in an  [out] VARIANT). the IRecordInfo should be released, too.
("should" means "otherwise, a lot of existing code would break/be broken").
Some more info here: http://vcfaq.mvps.org/com/4.htm


Erro ao rodar o comando db:seed

Question: Estou estudando laravel na versão 5.2 e ao executar o comando php artisan db:seed retorna o seguinte erro:

[InvalidArgumentException]
    Unable to locate factory with name [default] [CodePub\Models\User].

<?php

use Illuminate\Database\Seeder;

class UsersRolesPermissionsSeeder extends Seeder
{
/**
 * Run the database seeds.
 *
 * @return void
 */
public function run()
{
    $user = factory(\CodePub\Models\User::class)->create([
        'name' => 'Admin da Silva',
        'email' => 'email@example.com',
        'password' => bcrypt(123456)
    ]);

    $roleAdmin = factory(\CodePub\Models\Role::class)->create([
        'name' => 'Admin',
        'description' => 'System Administrator'
    ]);

    $user->addRole($roleAdmin);

    $userManager = factory(\CodePub\Models\User::class)->create([
        'name' => 'Manager da Silva',
        'email' => 'firstname.lastname@example.com',
        'password' => bcrypt(123456)
    ]);

    $roleManager = factory(\CodePub\Models\Role::class)->create([
        'name' => 'Manager',
        'description' => 'System Manager'
    ]);

    $userManager->addRole($roleManager);

    $userSupervisor = factory(\CodePub\Models\User::class)->create([
        'name' => 'Supervisor da Silva',
        'email' => 'firstname.lastname@example.com',
        'password' => bcrypt(123456)
    ]);

    $roleSupervisor = factory(\CodePub\Models\Role::class)->create([
        'name' => 'Supervisor',
        'description' => 'System Supervisor'
    ]);

    $userSupervisor->addRole($roleSupervisor);

}
}

DatabaseSeeder.php
<?php

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
/**
 * Run the database seeds.
 *
 * @return void
 */
public function run()
{
    // $this->call(UserTableSeeder::class);
    $this->call(UsersRolesPermissionsSeeder::class);
}
}

Answer: Como está definindo os dados diretamente poderá usar somente o arquivo DatabaseSeeder.php como na documentação da seguinte forma:
 DB::table('users')->insert([
            'name'              => 'Admin da Silva',
            'email'             => 'firstname.lastname@example.com',
            'password'          => bcrypt(123456),
        ]);

Agora, se for usar o factory juntamente com fake, faltou definir os modelos no arquivo ModelFactory.php, que seria algo assim:
$factory->define(App\User::class, function (Faker\Generator $faker) {
    return [
        'name' => $faker->name,
        'email' => $faker->email,
        'password' => bcrypt(str_random(10)),
    ];
});

Para chamar o modelo definido acima na factory crie um seeder:
php artisan make:seeder TableNameSeeder

E chame da seguinte forma:
factory(App\User::class, 10)->create();

Sendo o número 10 a quantidade de registros que deverão ser inseridos no banco dados.
E no arquivo que controla o seed -> DatabaseSeeder.php, chame a função normalmente como descrito na pergunta:
$this->call(TableNameSeeder::class);

Acho que é isso!
Espero ter ajudado!

Erro ao rodar o comando db:seed


Given a set of points in 2d coordinates system, how to calculate the minimum distance and the path if we visit all the points only once?

Question: The limit conditions are as below:

A fix threshold is set which makes distance larger than threshold are calculated by the distance itself
and distance less than or equal to distance are regarded as a constant value;
It is better to let the path increases with the x coordinates (that is p1.x <= p2.x <= ... <= pn.x),
but condition.1 is considered first, then the condition.2;
We can only visit each point for only once.
Comment: Sounds like a variation of the [travelling salesman problem](https://en.wikipedia.org/wiki/Travelling_salesman_problem).
Answer: Note for optimization: So, basically a shortest Hamiltonian path with 2 twists (condition 1 & 2). Considering shortest HP can be solved with a Travelling Salesman algorithm (with a dummy city with zero distance from all others), for a better optimised solution you could try manipulating your distance matrix according to condition 1 before feeding it to a TSP algorithm.
More on how to use TSP for this shortest HP here.
Brute force approach
I'm gonna call your points [A, B, ...C] for readability. Let's represent our points like this:
<code>+---+---+---+
|   | X | Y |
+---+---+---+
| A | 0 | 0 |
| B | 4 | 3 |
| C | 0 | 3 |
+---+---+---+
</code>
Then create a distance matrix with the Pythagorean theorem:
<code>+---+------+------+------+
|   |  A   |  B   |  C   |
+---+------+------+------+
| A | 0.00 | 5.00 | 3.00 |
| B | 5.00 | 0.00 | 4.00 |
| C | 3.00 | 4.00 | 0.00 |
+---+------+------+------+
</code>
My understanding of your first condition (fix threshold) is that any distance lower than a certain value is considered zero. Apply that condition to the distance matrix (let's say it's 3.50 in our case).
<code>+---+------+------+------+
|   |  A   |  B   |  C   |
+---+------+------+------+
| A | 0.00 | 5.00 | 0.00 |
| B | 5.00 | 0.00 | 4.00 |
| C | 0.00 | 4.00 | 0.00 |
+---+------+------+------+
</code>
Now, if we keep to our brute force approach, we must fund all possible permutations of routes. In our case, it's going to be simply
<code>+------+-----------+--------------+
| Path | Distances | Total Length |
+------+-----------+--------------+
| ABC  | 5+4       |            9 |
| ACB  | 0+4       |            4 |
| BAC  | 5+0       |            5 |
| BCA  | 4+0       |            4 |
| CAB  | 0+5       |            5 |
| CBA  | 4+5       |            9 |
+------+-----------+--------------+
</code>
Remove routes that are the same but reverse.
<code>+------+-----------+--------------+
| Path | Distances | Total Length |
+------+-----------+--------------+
| ABC  | 5+4       |            9 |
| ACB  | 0+4       |            4 |
| BAC  | 5+0       |            5 |
+------+-----------+--------------+
</code>
Take the shortest by total length and that is your solution.
2nd condition - distance covered on X is preferable to distance covered on Y
As far as I understood, this condition only activates if there is a tie in Total Length. In that case, create a distance matrix by using the absolute value of the difference in the points' X coordinates:
<code>+---+------+------+------+
|   |  A   |  B   |  C   |
+---+------+------+------+
| A | 0.00 | 4.00 | 0.00 |
| B | 4.00 | 0.00 | 4.00 |
| C | 0.00 | 4.00 | 0.00 |
+---+------+------+------+
</code>
Sum up the distances according to your tied routes and use the min of that to decide which one should be preferred.


Using classes in PHP

Question: I'm trying to coding my PHP scripts with classes but it is very difficult to learn. The transition from the old style making me trouble. I know why to use classes but my question is. Can I code everything using classes? Is it effective? Or sometimes "the old style" is better.
Ok. I try to be more specific. Can be this code write with classes?
<code><?php
$error = array("Odpad nebol zapísaný!");
if (isset($_POST["submit"])) {
$note = isset($_POST['note']) ? $_POST['note'] : '';
$rozmer=$oznacenie_pracoviska=$oznacenie_odpadu=$meno=$vaha=$zberne_miesto="";

if (is_numeric($_POST["zakazka1"]) && is_numeric($_POST["zakazka2"]) && is_numeric($_POST["zakazka3"])) {

    function countDigits($str) {
    return preg_match_all( "/[0-9]/", $str );
    }

    if (countDigits($_POST["zakazka1"])==3 && countDigits($_POST["zakazka3"])==2) {
        $zakazka = array($_POST["zakazka1"],$_POST["zakazka2"],$_POST["zakazka3"]);
        $zakazka_cela = implode("/", $zakazka);
    }

    else {
        $error[]="Zadajte správny počet číslic v zákazke!";
    }

}

else {
   $error[]="Zadajte číslo zákazky!";
}

if (empty($_POST["rozmer"])) {
    $error[]="Zadajte rozmer!";
}

else {
    $rozmer=$_POST["rozmer"];
}

if (empty($_POST["oznacenie_odpadu"])) {
    $error[]="Zadajte označenie odpadu!";
}

else {
    $oznacenie_odpadu=$_POST["oznacenie_odpadu"];
}

 if (empty($_POST["vaha"])) {
    $error[]="Zadajte váhu!";
}

else {
    $output = str_replace(',', '.', $_POST["vaha"]);

    if (is_numeric($output)) {
        $vaha = str_replace('.', ',', $_POST["vaha"]);
    }

    else {
       $error[]="Váha zadaná v zlom formáte!";
    }
}

if (empty($_POST["oznacenie_pracoviska"])) {
    $error[]="Zadajte označenie pracoviska!";
}

else {
    $oznacenie_pracoviska=$_POST["oznacenie_pracoviska"];
}

 if (empty($_POST["meno"])) {
    $error[]="Zadajte meno!";
}

else {
    $meno=$_POST["meno"];
}

if (empty($_POST["zberne_miesto"])) {
    $error[]="Zadajte kód zberného miesta!";
}

else {
    $zberne_miesto=$_POST["zberne_miesto"];
}

}
</code>
Comment: You could code this snippit in a class, but it wouldn't be a very good class. In terms of doing something, it's not really doing anything except some basic validation and error handling. I think it would need to be part of a bigger task so whatever you are using this for might be more useful for the rest of the class.
Comment: not sure what you mean by `Old Style` but php thrives on OOP for security and DRY-ness (don't repeat yourself) knowing how classes work will make PHP a million times more fun to use. Do you have a specific question on classes? or the ideologies behind them? if not I have to flag this as "Too Broad" :/
Comment: I believe the `Zend` framework prides itself on being 100% OOP instead of procedural....aka *"Old style"*, so yes, it is possible to code everything with classes.
Answer: First of all OOP is not difficult to learn. If your brain starts thinking that it is difficult so you will never be able to learn it properly and you will never enjoy the OOP style. OOP php has a lot of effective features which makes programming easier and more readable. Start learning OOP in php and i am sure you will enjoy it. You can do everything in OOP what you can do in procedural. although you can use classes in procedural style and that is also an awesome way of PHP programming.

Using classes in PHP


Recover deleted LVM signature

Question: I guess I've deleted LVM partition. I expanded the datastore in vmware ( 70 GB to 90 GB ), then I run echo 1> /sys/class/block/sdb/device/rescan.
After that I run fdisk /dev/sdb. it shows my sdb is 90 GB but with this warning :
The old LVM2_member signature will be removed by a write command.
I did enter w which I guess was a bad idea.
Now none of these commands show anything: lvs, vgs, pvs
With blkid I see my sdb UUID has changed:
/dev/sda1: UUID="b96e5429-d28e-4102-9085-4f303642a26e" TYPE="ext4" PARTUUID="0ab90198-01"
/dev/mapper/vg00-vol_db: UUID="4ed1927e-620a-4bf9-b656-c208f31e6ea3" TYPE="ext4"
/dev/sdb: PTUUID="d6c28699" PTTYPE="dos"

I run vgcfgrestore vg00 --test -f vg00_00001-2029869851.vg which is the last file before today's changes. (it's for 2 months ago when I created the LVM)
But it returned
  TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.
  Couldn't find device with uuid 4deOKh-FeJz-8JqG-SAyX-KviL-UGu4-PtJ138.
  Cannot restore Volume Group vg00 with 1 PVs marked as missing.
  Restore failed.

How can I restore this mess ? Thanx a lot
Answer: I know it's an old topic but I think it would be useful for others as I just made the very same mistake but I managed to make it work (quite) easely.
Download gparted cd, boot on it.
Open a terminal and
sudo hexedit /dev/sda3

(where sda3 is your broken partition)
scroll with arrows to 00000200
There you should have lines looking like these:
00000200  4c 41 42 45 4c 4f 4e 45  01 00 00 00 00 00 00 00  |LABELONE........|
00000210  fe b5 f2 9a 20 00 00 00  00 00 00 00 00 00 00 00  |.... ...........|
00000220  42 32 42 4e 66 78 44 54  41 79 55 67 57 65 77 41  |B2BNfxDTAyUgWewA|
00000230  70 4e 32 42 57 4e 4f 64  52 36 6e 74 55 6f 44 4d  |pN2BWNOdR6ntUoDM|

Replace the line 210 with this code:
00000210  fe b5 f2 9a 20 00 00 00  4c 56 4d 32 20 30 30 31  |.... ...LVM2 001|

press F2 to save, CTRL + X to exit and reboot.
Voila !
Comment: This helped me as well, thank you!
Answer: Start logging your terminal session to have a record of what you did.
Start your backup restore procedures in case data was lost. Request tapes or archive storage. Do not start copying data yet.
Consider imaging the broken PV's block device, to protect against a repair making things unrecoverable. Especially if it is easy to do, like with a storage array snapshot.
Follow a procedure to restore metadata on an LVM physical volume. Fill in the commands with the broken PV, being aware that an incorrect value may lose data. In particular, double check if the block device is the entire disk /dev/sdb, or is some partition like /dev/sdb1. You didn't print the partition table, so I cannot be sure.
 pvcreate --uuid 4deOKh-FeJz-8JqG-SAyX-KviL-UGu4-PtJ138 --restorefile vg00_00001-2029869851.vg blockdevice
 vgcfgrestore vg00
 lvchange --activate y
 fsck

Spot check data is there to your satisfaction.

In some form of after action review, examine how data protection could be improved.
Check if backups met the recovery time objective. Say you have a policy to be able to restore to last night. If a nightly backup was not there, or not documented, fix that.
Consider creating future LVM PVs on entire disks. Avoids the partitioning complication, skipping fdisk steps. Linux LVM is perfectly fine with a PV on /dev/sdb.

Recover deleted LVM signature


How to know whether MERGE "Upsert" Inserted or Updated?

Question: I'm new to MERGE - I have a MERGE statement that works:
merge customers with (holdlock) as c
using (select @id as id) as new_id
  on c.contactid = new_id.id
when matched then
  update set ContactID = 1, firstname = CAST(SYSDATETIME() AS VARCHAR(100))
when not matched then
  insert(ContactID) values(1), firstName = 'b';

(the SQL doesn't really matter - this was for testing purposes).
I've googled this but can't find the answer, I'm unclear on why no 'updated' is returned.
My question is - how could I return something indicating whether an Insert or Update happened?
Comment: I don't understand down votes on this question. The answer below requires a fairly advanced knowledge of SQL.
Comment: you can create two columns to your table like CreatedDate and ModifiedDate. In merge when insert happens insert GetDate() in the CreatedDate column, when update occurs set ModifedDate as GetDate(). If ModifedDate column is null then it means only insert occurred and when it has value it means it get updated.
Comment: that is one option - though seems the answer below is better as it doesn't require schema changes.
Answer: You can use the OUTPUT clause in your merge statement with the key word $action.
Something like....
merge customers with (holdlock) as c
using (select @id as id) as new_id
  on c.contactid = new_id.id
when matched then
  update set ContactID = 1, firstname = CAST(SYSDATETIME() AS VARCHAR(100))
when not matched then
  insert(ContactID) values(1), firstName = 'b'

OUTPUT $action, inserted.*, deleted.*;

The above output clause will return the action was taken in the first column like update , insert or delete and the values from inserted and deleted tables.
Comment: @niico: The two SQL Server pseudo tables, inserted and deleted, are all you need to view the changes from an insert, an update or a delete.   The deleted table shows rows before they were deleted or updated.  The inserted table shows rows after they were inserted or updated.  So, for updates, the deleted table shows the state of the updated rows before the update and the inserted table shows the state of the updated rows after the update.  There is no need for an updated pseudo table.
Comment: Dude.... google it http://www.made2mentor.com/2013/06/using-the-output-clause-with-t-sql-merge/
Comment: I have since ascertained that inserted.* or deleted.* include the deleted or inserted rows in the returned output. I'm still unclear why there's no updated.*
Comment: thanks - why "inserted.*, deleted.*" - what does that do also why no "updated.*"?
Comment: Your link doesn't actually explain what inserted.* or deleted.* does. I googled it and can find no explanation anywhere - it also appears to have no effect on my output over just OUTPUT $action.


How to practice for piano with chord in one hand and lead in another?

Question: I am used to playing any song with both of my hand as I am good with harmonium in which with one hand you have to wave a door to flow air. But when it comes to playing actual notes (i.e., lead/melody) of a song with one hand and chords with another hand, I am not able to play that. What exercise or advice would help me with this?
If I need to play chords with both hand or lead notes with both hands, then I am able to play it. But I can't do this concurrently or simultaneously, such that one hand has the lead/melody and the other hand has the chords.
I do play chords naturally, but I don't know staff notation as I learned the North Indian classical notation system sa re ga ma pa dha ni.
Comment: I'm going to mark your question as a duplicate, because someone else asked a question about learning both hands on the piano. A link to the duplicate will appear below this comment, and if you click on that link, you should see several answers that should help you with learning to play with both hands. If you still need help after reading those answers, you can either edit your question here or ask a new question. Welcome to Music Practice & Theory!
Comment: @ToddWilcox i read that question in that asker did not mentioned about   chords with one hand and lead notes with another i can play with both hand chords and both hand lead but not alter at same time. so slightly different.
Comment: The other question is not specific to what notes are being played with what hand. Any combinations of notes are considered by the other question. Very often with piano music the two hands are playing very different parts. That's what the other question is about. Your situation is that you want to play different parts with each hand. The answers to the other question tell you how to learn to play two different parts at the same time.
Comment: I think this is a great question, and I do think it's very similar to the one @ToddWilcox linked to. Check out the first answer under the link Todd shared. I believe that answer contains the sort of strategies you are looking for. If it doesn't, then perhaps you could edit the question as Todd suggested, and state "I'm looking for strategies specifically relating to playing chords in the left hand" and explain why the other answer doesn't do the trick.
Comment: @jdjazz its contains strategies of playing simultaneously notes (or at least that what i understand) means some of notes that is need to play by right hands that are lower scale and than some of higher that needs to be play on higher scale. i want to practice to give press with two or one or more fingers with my left hand and play lead notations with my right hand and as song move on change respected finger chords with my left hand. found it very difficult.
Answer: The most effective method I have found is to begin like so:
Situate yourself at the piano comfortably, and strike the desired first chord with the left hand, and slowly begin to explore the desired lead melody with the right.
Depress the sustain pedal and let that one chord ring as you practice the lead notes.
Do not attempt to phrase the song's complete rhythm and tempo, but rather, just strike that one chord and let it be enough, in the early stages of your practice.
Then strike the next chord in order, and let it ring as you practice the melody lines. One chord after the next, not attempting to properly play the target song exactly, just laying down a baseline for the muscle memory.
After one or two sessions of this, you will come to realize that your instinct for playing the lead runs with your right hand is comfortable, and you have found the left hand chord phrasings instinctively also. You're just building muscle memory, remember.
When you feel ready, graduate yourself to striking the desired song tempo and chord rhythms with the left hand, and just touch the key notes with your right, not all of them. In this regard, you are building the muscle memory for the desire end state in your left hand.
Within a day or so, you will find that you can play the entire song.
It's a 'crawl, walk, run' progression of practice.
Good luck!
Comment: great so first only one chord and its related notes without tempo and rhythm than another part. so dividing lead notation as per chords than practice individual and later joined in Synced that made sense. any melody you have in mind? to get started with. your answer sounds like you have a lot experience. and thanks


How to properly explain a delta between 0.10 to 0.05 in proportions

Question: Assuming I have proportions for clicks to impressions of 0.10 for p1 and 0.05 for p2. This is equivalent to 10% and 5% click through rate.
One way is to say that p1 is 5% higher but can we even say that p1 is 100% more than p2 ? If so what is the best possible way to word this to not confuse the reader if only the delta is displayed and not the ratios
Option 1) The first proportion is 5% higher ?
Option 2) There is a 100% delta between both proportions
Edit: Typo in my delta number example (changed it)
Comment: "P1 is 2-fold larger than P2". This wording is as ambiguous as "twice as large", but works for any decimal values rather than just round numbers like 2.
Answer: As stated by Dave, $p_1$ is $100\%$ more than $p_2$, not $50\%$ (now corrected in the question), and is equivalent to saying that it is twice as much.
As for the other way of saying it (option 1), I believe that the convention generally is to say that $p_1$ is 5 percentage-points higher than $p_2$.
Answer: $p_1$ is not $50\%$ higher than $p_2$; $p_1$ is $100\%$ higher than $p_2$.
I would phrase it accordingly: $p_1$ is double $p_2$. After all, I would expect the event under consideration to happen twice as often under the conditions giving $p_1$ as under the conditions giving $p_2$.
In other words, if you make a dollar every time the event happens, you make twice as much money with $p_1$ as with $p_2$.
Comment: assuming one can only show percentages and not words as such "double ..." this is in the context of ab testing
Answer: There isn't really a single, 'correct' way to describe the relationship between two proportions.  The issue here is how to give a measure of the size of an effect when the constituent measures are proportions of known totals.  The effect size for comparisons of continuous variables with natural zeros is straightforward, but with binary data, there are inescapable complexities.  Unfortunately, there is no perfect solution to that problem whereby you get all the advantages of every option and none of the disadvantages.  Moreover, which measure of effect size should be used for such a situation has long been a source of contention.  For what it's worth, the three major contenders are:

The risk difference (your option 1), which is $.05$ in your case.  People like it because subtraction is simple and the measure seems very intuitive.  A problem is that, in general, $.05$ probably does not equal $.05$ (e.g., it is likely much harder to improve your click-through rate from $.10$ to $.15$ than it is to improve it to $.10$ from $.05$, as the pool of potential customers is shrinking within the group that sees your ad).

The risk ratio (more or less your option 2), which is $2$ in your case.  People similarly like this as relatively intuitive.  Note however that successive increments with the same numerical value are again unlikely to be truly equal (similar to the above; here: $.1/.05 \ne .2/.1$), and that the measure is unintuitively asymmetrical (i.e., comparing $p1$ to $p2$ yields $2$, but comparing $p2$ to $p1$ gives $.5$).

The odds ratio (which you did not list), which would be $\approx 2.11$ in your case.  With the odds ratio, it is at least theoretically possible to have a constant increment forever, and the odds ratio also plays an important role in logistic regression.  On the other hand, the odds ratio isn't even remotely intuitive, and suffers from a technical problem called 'non-collapsibility'.

In your case, you have just two numbers.  It is probably easiest to just present them.  If you have to say it's either 'five percentage points higher' or 'twice as high', I would focus on which is likely to be more readily and correctly understood by your audience.  I might further consider a case where you were able to be twice as effective, would the result then be closer to $.15$ or $.20$?
Comment: love the answer. I just think that in the context of ab testing specifically in cases where we're evaluting click through rates. if control is 20% while test is 15%, i dont see the logic in doing the relative % difference when the actual true change is simply 5%. I think that in this case , presenting the difference in %s is leading to more confusion than not ?
Comment: @RogerSteinberg, that's fine.  It's a judgement call for you to make based on your context & your audience.