A bunch of code snippets that may help you ;)
Basically a repository with handy code snippets. Not only related to programming languages, but can also be related to frameworks, technologies, etc.
To centralize a JFrame in the middle of the screen use this.setLocationRelativeTo(null);.
Sort a list of dictionaries based on a key.
# e.g.: [{'name': 'Boyhood', 'year': 2014}, {'name': 'Citizen Kane', 'year': 1941}, {'name': 'Mad Max: Fury Road', 'year': 2015}]
# sortedList(aList, 'year')
def sortedList(aList, aKey):
return sorted(aList, key=lambda k: k[key])It is also possible to sort by a key of a key.
sorted(anotherList, key=lambda k: k['release_date']['year'])Read a file ALL.csv and covert all the strings in the column to a comma-separated string.
names <- readLines("ALL.csv")
listOfNames <- ""
for (i in names) { listOfNames <- paste(listOfNames, "," , i) }
listOfNames <- gsub(" ", "", listOfNames)
substr(listOfNames, 2, nchar(listOfNames))Use HTTPS/SSL on your web application. Don't forget to pip install flask_sslify.
from flask_sslify import SSLify
sslify = SSLify(app)Import your app.config from a file.
app.config.from_object('<file_name>')
app.config.get('CORS_HEADERS')Using a placeholder in your WTForms form. Don't forget to pip install wtforms.
name = StringField('Name', render_kw={"placeholder": "Your name in here"})Use HTTPS/SSL on your web application. Don't forget to npm install express-force-https.
var secure = require('express-force-https');
var app = express();
app.use(secure);Use an HTTP request and create a promise.
var deferred = $q.defer();
# correct: deferred.resolve(response.data);
# error: deferred.reject(err);
return deferred.promise;Use -s option to show all prints when using pytest command.
-
travis encrypt-file config.ini --allRun this command to encrypt the file
config.iniand add the reference to.travis.yml.
Notable commands:
:qto close the file. Use!to force quit.:wto save your file./<word>to search for a<word>, if you want to keep searching, type/.ddto delete a line.ito enter INSERT mode.escto leave the INSERT mode.vto select the text (orVto select the whole line).dto cut,yto copy andPto paste.
- Check your systems specs on your Terminal:
lshw. Use--shortto show a short version.
These commands are valid for Linux and macOS.
tail -f foo.logto keep the file opened and showing the last updates on your file. Very useful for system logs.touchto create a new file.mkdirto create a new directory.pwdto show the current path.whoamito show the current logged user.
say <something>and your Mac will say<something>to you.