recentpopularlog in
« earlier  
Primer on Python Decorators – Real Python | https://realpython.com/
<code class="language-python">
def repeat(_func=None, *, num_times=2):
def decorator_repeat(func):
@functools.wraps(func)
def wrapper_repeat(*args, **kwargs):
for _ in range(num_times):
value = func(*args, **kwargs)
return value
return wrapper_repeat

if _func is None:
return decorator_repeat
else:
return decorator_repeat(_func)
</code>
python  newbie  language  idiom  decorators  solution 
9 hours ago
How to pass password to mysql command line - Unix & Linux Stack Exchange | https://unix.stackexchange.com/
It doesn't look like you can send a password to 'mysql' on stdin, even though that's where it seems to be expecting it from with the '-p' (no password) option.

So I ended up using the '--defaults-file' option.
mysql  cli  dba  commandline  pipes  subprocess  python  workaround  solution 
17 hours ago
python - SQLAlchemy default DateTime - Stack Overflow | https://stackoverflow.com/
You could use 'server_default=func.now()', but that will calculate a timestamp once per transaction, which may not be what you want.

This probably works fine:

<code class="language-python">
import datetime
from sqlalchemy import Column, Integer, DateTime
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class Test(Base):
__tablename__ = 'test'

id = Column(Integer, primary_key=True)
created_date = Column(DateTime, default=datetime.datetime.utcnow)

</code>
python  sqlalchemy  sql  timeanddate  timestamp  dba  solution 
19 hours ago
perl - How can I set default values using Getopt::Std? - Stack Overflow | https://stackoverflow.com/
The best thing is to use GetOpt::Long and use a hash instead of individual variables. Then you can pass default values by pre-populating the array
<code class="language-perl">
use Getopt::Long;
my %opts = (parameter => 20);
GetOptions( \%opts,
'p|parameter=i',
'o|outputfile=s',
'i|inputfile=s'
) or die "Invalid parameters!";
</code>
perl  argumentprocessing  shellscripting  getopt  solution 
yesterday
MySQL :: Re: repair by sorting? | https://forums.mysql.com/
"Repair by sorting" is MyISAM's way of updating the indexes after a bulk insert. When inserting Millions of rows of data into a MyISAM table, it is normal for the index updates to take longer than the actual inserts.
mysql  dba  errormessage  solution 
5 days ago
innodb - Internal reason for killing process taking up long time in mysql - Database Administrators Stack Exchange | https://dba.stackexchange.com/
Possible causes: InnoDB takes forever to roll back mass inserts. Also, innodb_buffer_pool_size might've been too small (default is only like 128 MB).
innodb  mysql  performance  optimization  errormessage  itsslow  maybesolution 
5 days ago
UCSC MySQL | http://lh3lh3.users.sourceforge.net/
The binning algorithm is in section 5.3 of the SAM specification (https://samtools.github.io/hts-specs/SAMv1.pdf?page=18).
A note on binning

For small tables like refGene, UCSC simply creates MySQL indices on the chromosomal coordinate of a record. For large tables like snp129, UCSC cacluates a bin number for each record and only indexes chromosome name and the bin number without indexing chromosomal coordinates. Doing in this way is faster than simply relying on the MySQL indices and saves disk space as well. Detailed algorithm can be found in Kent et al. (2002) or from the SAM format specification. You can also read the source code of this script to see how the bin number is calculated and used in query.
binning  mysql  ucsc  genomebrowser  dba  optimization 
5 days ago
Index of /bin/linux/ubuntu | https://cran.r-project.org/
Some people have reported difficulties using this approach. The issue is usually related to a firewall blocking port 11371. If the first gpg command fails, you may want to try (thanks to Mischan Toosarani for the tip):
<code class="language-bash">
gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
</code>

and then feed it to apt-key with
<code class="language-bash">
gpg -a --export E298A3A825C0D65DFD57CBB651716619E084DAB9 | sudo apt-key add -
</code>

Another alternative approach is to search for the key at http://keyserver.ubuntu.com:11371/ and copy the key to a plain text file, say key.txt. Then, feed the key to apt-key with
<code class="language-bash">
sudo apt-key add key.txt
</code>
r  installation  ubuntu  packages  keyserver  errormessage  workaround  solution 
6 days ago
apt - "GPG error:The following signatures were invalid: KEYEXPIRED" - Ask Ubuntu | https://askubuntu.com/
That ppa has been removed and no longer exists. You must find a different source for the packages installed through the samrog131 ppa.

In the meantime, run the following commands to resolve the situation.

First, to delete the expired key:
<code class="language-bash">
sudo apt-key del 1436387333
</code>

Then, to delete the ppa:
<code class="language-bash">
sudo rm /etc/apt/sources.list.d/samrog131*
sudo apt-get clean
sudo apt-get update
</code>

If you need to add a key see here.
<code class="language-bash">
sudo apt-get upgrade
</code>

You may want to run:
<code class="language-bash">
sudo apt-get dist-upgrade
</code>

depending on your situation. If you are not sure, see here.
ubuntu  apt  packagemanagement  crypto  pubkey  errormessage  solution 
6 days ago
linux - How to strip path while archiving with TAR - Stack Overflow
In your "Extraction phase" you can use the strip-components flag like
<code class="language-bash">tar xvf tarname.tar --strip-components=n</code>
tar  archive  decompression  tipsandtricks  commandline  shellscripting  solution 
7 days ago
gnu make - makefile: concatenate text with infix operator - Stack Overflow | https://stackoverflow.com/


Louis is correct: there's no magical way of doing this. But if, instead of trying to remove the last item or treat it specially, you instead treat the first item specially, the work is much simpler to understand (I think); you can create a function combine that takes two arguments: the first is the text to put between the words and the second is a space-separated list of words to combine:
<code class="language-makefile">combine = $(word 1,$2) $(foreach W,$(wordlist 2,$(words $2),$2),$1 $W)</code>

Now you can use it like this:
<code class="language-makefile">$(call combine,-o,$(EXCLUDE_LIST))</code>

to get output like:
<code class="language-">$(BASE_DIR)/aaa* -o $(BASE_DIR)/bbb*</code>
devel  build  toolchain  makefile  stringfunctions  workaround  solution 
7 days ago
firebug - Access variables in jsFiddle from Javascript console? - Stack Overflow | https://stackoverflow.com/
With Firefox (34+) and the new Firefox Developer Edition, it's possibile to do the same by enabling the Select a frame as the currently targeted document extra tool into the developer tools, then click on it and select http://fiddle.jshell.net/_display/.
jsfiddle  webdevel  console  devtools  jquery  solution 
7 days ago
MySQL show status: How to show open database connections | alvinalexander.com | https://alvinalexander.com/
<code class="language-bash">
$ mysqladmin status
$ mysql dbname -e "show status like '%onn%';"
$ mysql dbname -e "show processlist;"</code>
mysql  dba  mysqladmin  admin  solution 
7 days ago
installation - ImportError: module 'setuptools.dist' has no 'check_specifier' attribute - Stack Overflow | https://stackoverflow.com/
It was due to older setuptools version. I updated setuptools as follows:
<code class="language-bash">sudo pip install setuptools --upgrade</code>

It installed setuptools-31.0.0 and that worked.
pip  python  centos6  errormessage  packaging  installation  solution 
8 days ago
macos - Case-insensitive ls sorting in Mac OSX - Ask Different | https://apple.stackexchange.com/
I needed sort's '-V' (version string sort) option, and here's how I got that:
Install the GNU Coreutils package:

sudo port install coreutils
sorting  textprocessing  bsd  mac  osx  shellscripting  workaround  solution 
9 days ago
how to display local shell-script/s in browser/firefox? - Unix & Linux Stack Exchange | https://unix.stackexchange.com/
The way data is processed in a browser depends on the MIME type declared by the server. If you want your browser to render it as html, which is most likely a terrible idea, you can change the Content-Type header the server returns so that it reflects the type of your data, which would be text/html; charset=utf-8, and the Content-Disposition header to suggest the browser what to do.

My solution was the following (in a '.htaccess'):
<code class="language-apache">
<Files *.sh>
SetEnvIf Request_URI "([^/]+\.sh)" FileName=$1

# ref: https://unix.stackexchange.com/a/364433
Header set Content-Type "text/plain"

# not needed, and doesn't work alone, since the browser is configured to
# download "application/sh" rather than display it inline; just telling the
# browser it's "text/plain" is enough to achieve the aim
#Header set Content-Disposition "inline; filename=\"%{FileName}e\""
</Files>
</code>
firefox  browser  mimetype  contentdisposition  webmaster  apache  configuration  solution 
13 days ago
http headers - How do I force files to open in the browser instead of downloading (PDF)? - Stack Overflow | https://stackoverflow.com/
To indicate to the browser that the file should be viewed in the browser:
<code>
Content-Type: application/pdf
Content-Disposition: inline; filename="filename.pdf"
</code>

To have the file downloaded rather than viewed:
<code>
Content-Type: application/pdf
Content-Disposition: attachment; filename="filename.pdf"
</code>

The quotes around the filename are required if the filename contains special characters such as filename[1].pdf which may otherwise break the browser's ability to handle the response.
httpd  apache  webmaster  headers  contentdisposition  sortof  solution 
13 days ago
loop over characters in input string using awk - Stack Overflow | https://stackoverflow.com/
You can convert a string to an array using split:
<code class="language-bash">
echo "here is a string" | awk '
{
split($0, chars, "")
for (i=1; i <= length($0); i++) {
printf("%s\n", chars[i])
}
}'
</code>

This prints the characters vertically, one per line.
awk  arrays  textprocessing  shellscripting  solution 
13 days ago
Is it possible to create a multi-line string variable in a Makefile - Stack Overflow | https://stackoverflow.com/
Yes, you can use the define keyword to declare a multi-line variable, like this:
<code class="language-makefile">
define ANNOUNCE_BODY
Version $(VERSION) of $(PACKAGE_NAME) has been released.

It can be downloaded from $(DOWNLOAD_URL).

etc, etc.
endef
</code>

The tricky part is getting your multi-line variable back out of the makefile. If you just do the obvious thing of using "echo $(ANNOUNCE_BODY)", you'll see the result that others have posted here -- the shell tries to handle the second and subsequent lines of the variable as commands themselves.

However, you can export the variable value as-is to the shell as an environment variable, and then reference it from the shell as an environment variable (NOT a make variable). For example:
<code class="language-makefile">
export ANNOUNCE_BODY
all:
@echo "$$ANNOUNCE_BODY"

</code>
makefile  shellscripting  annoyance  solution 
13 days ago
Gene Frequently Asked Questions - Gene Help - NCBI Bookshelf | https://www.ncbi.nlm.nih.gov/
Here's probably the canonical reference for ftp://ftp.ncbi.nlm.nih.gov/gene/DATA/GENE_INFO/, where you can get aliases (and ENSG IDs) for all mammalian genes.
gene  geneid  genealias  bioinformatics  reference 
14 days ago
bash - .inputrc TAB not behaving as expected - Unix & Linux Stack Exchange | https://unix.stackexchange.com/
Readline doesn't know anything about a modifier called Shift, and quietly ignores unknown modifier names. Try wibble-TAB.
unix  bash  readline  inputrc  annoyance  workaround  solution 
14 days ago
You can make readline (and bash) much more user friendly by adding a few options to ~/.inputrc : commandline | https://www.reddit.com/
set completion-prefix-display-length 2

This one is insanely useful when you have a folder with lots of similarly named files and you are not sure how far the completion has gone when you press TAB. The first part that has been completed will be replaced by "...", and it is simple to see what you need to type to finish the completion.
inputrc  input  readline  bash  cli  configfile  configsettings  example  newbie  movein  essential 
14 days ago
« earlier      
per page:    204080120160

Copy this bookmark:





to read