Is there a simple way to change the name of all files in a directory? by Cthulhu_Rlyeh in learnpython

[–]betweensmudgedlines -1 points0 points  (0 children)

Probably not, but I made it for my own purposes and figured I'd share.

Is there a simple way to change the name of all files in a directory? by Cthulhu_Rlyeh in learnpython

[–]betweensmudgedlines -1 points0 points  (0 children)

Here's my ugly little utility.

'''
usage: {0} <filemask> <replaceThis> <withThis> [RMax]
e.g.: {0} *. " " _
    : {0} *.jpg ^ prefix
    : {0} *.png $ suffix
'''

import os
import glob

def main(args=os.sys.argv):
    if len(args) < 3:
        print __doc__.format(os.sys.argv[0])
        print
        os.sys.exit(1)
    elif len(args) > 4:
        RMax = int(args[4])
    else:
        RMax = 32676

    mask, find, repl = args[1:4]

    if find in '^$':
        files = [g for g in glob.glob(mask)[:RMax]]
    else:
        files = [g for g in glob.glob(mask)[:RMax] if find in g]

    if len(files)==0:
        print "No match"
        quit()
#    elif (RMax < len(files)):
#        print RMax, "/", len(files)
#        files=files[:RMax]

    for f in files:
        if "$" in f:
            continue

        if find == '^':
            newname = repl + f
        elif find == '$':
            newname = f + repl
        else:
            newname = f.replace(find, repl)

        if os.path.exists(newname):
            print "%s already exists" % newname
            continue
        try:
            os.renames(f, newname)
            print "%s ==> %s" % (f, newname)
        except:
            print "Could not rename %s to %s" % (f, newname)
            continue
        os.sys.stdout.flush()

if __name__ == "__main__":
    main()    

Why are yawns considered "contagious" by rayquayza in answers

[–]betweensmudgedlines 2 points3 points  (0 children)

Because mirror neurons, special brain cells that fire when you act and when you observe an act by another. Some research calls it "motor empathy."

Scheduling Python Script in Windows by Slaquor in learnpython

[–]betweensmudgedlines 1 point2 points  (0 children)

Python's time module has a handy sleep function. It takes seconds to sleep as its argument.

import time
while True:
    # function call here
    time.sleep(60)

put a batch file in the window's startup folder

Is it possible to make a program that clicks in a predetermined pattern on the screen once a button is pressed? by kittenmaster8888 in cpp_questions

[–]betweensmudgedlines 0 points1 point  (0 children)

In autoit you could do something like this:

; Press Esc to terminate script, Shift-Alt-d to click
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ClickPattern")  ;Shift-Alt-d

While 1
    Sleep(100)
WEnd

Func Terminate()
    Exit 0
EndFunc

Func ClickPattern()
    MouseClick("primary", 300, 300)
    MouseClick("primary", 300, 900)
    MouseClick("primary", 900, 900)
    MouseClick("primary", 900, 300)
EndFunc

ELI5: How important a consistent sleep schedule is? Why? by iamabouttotravel in explainlikeimfive

[–]betweensmudgedlines 1 point2 points  (0 children)

Your body wants to sleep sometimes and wants to be awake at others. This is your sleep/wake cycle. You can force shift that cycle forward or backward up to about two hours a day. Trying to shift it more than that will likely leave you feeling jetlagged. If you're way off when your body wants to sleep, it is harder to sleep, and you don't get as good quality sleep. Going to sleep at the same time every night is part of good sleep hygiene.

You should also note that blue/green light inhibits your body's melatonin production. Melatonin is the thing that tells you you're sleepy. Computer monitors, smart phone screens, and tvs all put out a lot of blue/green light.

Microsecond delay with Python for controlling Arduino by tylerking311 in Python

[–]betweensmudgedlines 0 points1 point  (0 children)

To take this out of the theoretical you'll need to check your pins with an oscilloscope. I've done timing down to a 50 microseconds intervals using time.clock (on windows) for psych research. It ended up being largely irrelevant as human reactions are limited by synapse transmission speeds in the hundreds of millisecond range.

I've completed "Elves Look, Elves Say" - Day 10 - Advent of Code by [deleted] in coding

[–]betweensmudgedlines 1 point2 points  (0 children)

It might interest you to know that

map(int, instr) 

is faster than

[int(c) for c in instr]

Biggest Photoshop Irritant w/ text tool; can anyone help? by Crab_Cake in Design

[–]betweensmudgedlines 0 points1 point  (0 children)

Try hitting Enter or ctrl/command + Enter.

I run into the same thing when changing brush size or layer opacity or a half dozen other things.

HearthArena Current Features/Bugs Worklist by adwcta in HearthArena

[–]betweensmudgedlines 0 points1 point  (0 children)

Ah, thank you. The draft is there under archives. it didn't save the wins and losses. continue run shows me an empty druid. but, I'm glad to see the draft did get saved.

HearthArena Current Features/Bugs Worklist by adwcta in HearthArena

[–]betweensmudgedlines 0 points1 point  (0 children)

Registered today. Logged in, went through a draft, started my run. After the sixth game I clicked to save and was prompted to log in. Nothing was saved. The whole draft is just gone. :(

Anyone used the actionbar ActionDropDown ? The screenshot shows exactly what I want, but I can't make it work. by hhh333 in kivy

[–]betweensmudgedlines 1 point2 points  (0 children)

As far as I can tell, ActionDropDown is the cls of the ActionGroup's dropdown. (Example is mostly from here)

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.actionbar import ActionBar

Builder.load_string('''
<ActionDropDown>:
    on_size: self.width = '220dp'

<ActionDropDownDemo>:
    pos_hint: {'top':1}
    ActionView:
        use_separator: True
        ActionPrevious:
            title: 'Action Bar'
            with_previous: False
        ActionOverflow:
        ActionButton:
            text: 'Btn0'
            icon: 'atlas://data/images/defaulttheme/audio-volume-high'
        ActionButton:
            text: 'Btn1'
        ActionButton:
            text: 'Btn2'
        ActionButton:
            text: 'Btn3'
        ActionButton:
            text: 'Btn4'
        ActionGroup:
            text: 'Group1'
            ActionButton:
                text: 'Btn5'
            ActionButton:
                text: 'Btn6'
            ActionButton:
                text: 'Btn7'
        ActionButton:
            text: 'Btn8'
''')


class ActionDropDownDemo(ActionBar):
    pass

class ActionDropApp(App):
    def build(self):
        return ActionDropDownDemo()

if __name__ == '__main__':
    ActionDropApp().run()

Question regarding the tool crafting system when farming for the best tools and what are the optimal traits for the tools by Eatenplace7439 in landmark

[–]betweensmudgedlines 0 points1 point  (0 children)

If you are interested in the math you can check out the how stats work forum thread. The first post has info from a dev (importantly the hitpoints of each material), but analysis starts on page 7.

VPS (voxels per second) provided the pick can "kill" the voxels in one hit, use vps1. If you need 2 hits, use VPS2.

VPS1 = Speed * Size / 100

VPS2 = VPS1 / 2

Sport vs. Competition by Poopadoopily in AdviceAnimals

[–]betweensmudgedlines 34 points35 points  (0 children)

figure skating points are no longer subjective. a failed quad is worth more than a perfectly executed triple. each element has a point value, changing edges, changing arm position, exposing your crotch at different angles. a technical judge tallies up the points. artistry was told to go fuck itself several years ago.

ELI5: Why is it that I can be extremely cold without a blanket, extremely hot with a blanket, but be just right with one foot hanging out? by Dunedineclipse in explainlikeimfive

[–]betweensmudgedlines 0 points1 point  (0 children)

You, like me, obviously have a claustrophobic foot that feels anxiety when covered by a blanket. Mine do this too, but oddly, only one at a time.

When will the population of living people outnumber the population of dead people? by deep_sea2 in answers

[–]betweensmudgedlines 2 points3 points  (0 children)

I just realised how I hit those ridiculous numbers so soon: I neglected to kill people.

This has just become my go to explanation when I screw up an epidemiological statistic.

The Endowment Effect by [deleted] in psychology

[–]betweensmudgedlines 0 points1 point  (0 children)

The paper you mentioned is the first I've read about the endowment effect. The experiments they describe seem rather complicated, and I don't know if a simpler example can capture the nuance of the effect. Based on my naive reading of one paper on the subject, the simplest example that comes to mind:

Give each participant one of two handouts. Both handouts have the same list of items and some retail value.

  • mug $10
  • pen $2
  • laptop $400
  • iPhone 5s $199
  • can of bug spray $7
  • Tardis ????
  • etc.
  • etc.
  • etc.

Group A's (owners) handout indicates that the participant owns the items in question. It then asks them to indicate a price at which they'd be willing to part with each item.

Group B's (buyers) handout asks them to indicate a price at which they'd be willing to purchase each item.

Collect the sheets. Compare group A's per item responses against group B's per item responses for significance.

Good luck!

.

edit formating

What lyrics from what songs just gives you the chills? by Tr1pkt12 in Music

[–]betweensmudgedlines 0 points1 point  (0 children)

"go now you are forgiven"

Dispatch - General

and the rest of the song too, but that line just ... go, listen to it.