find . -type d -print0 | while read -d '' -r dir; do
files=("$dir"/*)
printf "%5d file count for directory %s\n" "${#files[@]}" "$dir"
done
Credits: https://stackoverflow.com/questions/15216370/how-to-count-number-of-files-in-each-directory
2018-11-23
MacOS - How to count the number of files in a given directory (command line)
find "/Path/Directory Name" -type f | wc -l
MacOS - How to remove a folder (or file) without being prompted for yes/no confirmations
rm -r "/Path/Target folder name"
MacOS - How to copy files using the command line, and avoid yes/no confirmation prompts
cp -av "original file name.ext" "\destination\path\target file name.ext"
2018-09-27
MacOS - Command line zip file creation
Several sample commands:
find ~/Documents/unzipTest -type f -name "*.zip" -exec unzip {} -d ~/Documents/unzipTest/ \;
find ~/Documents/unzipTest -type f -name "*.zip" -print0 | xargs -0 -I{} unzip {} -d ~/Documents/unzipTest
find <path_of_your_zips> -type f -name "*.zip" -exec unzip {} -d <out> \;
find <path_of_your_zips> -type f -name "*.zip" -exec unzip {} -d <out> \;
find /Users/ca/Documents/unzipTest/ -type f -name "*.zip" -exec unzip {} -d ~\Documents\unzipTest\ \;
find /Users/ca/Documents/unzipTest -type f -name "*.zip"
find ~/Documents/unzipTest -type f -name "*.zip" -exec unzip {} -d ~/Documents/unzipTest/ \;
find ~/Documents/unzipTest -type f -name "*.zip" -print0 | xargs -0 -I{} unzip {} -d ~/Documents/unzipTest
find <path_of_your_zips> -type f -name "*.zip" -exec unzip {} -d <out> \;
find <path_of_your_zips> -type f -name "*.zip" -exec unzip {} -d <out> \;
find /Users/ca/Documents/unzipTest/ -type f -name "*.zip" -exec unzip {} -d ~\Documents\unzipTest\ \;
find /Users/ca/Documents/unzipTest -type f -name "*.zip"
2018-09-11
JavaScript - Isotope, how to know if the object was successfully made an isotope
var iso = $('.grid').data('isotope');
if(iso) console.log("Object .grid has been isotope'd!");
if(iso) console.log("Object .grid has been isotope'd!");
JavaScript - Isotope object properties inspection, export JSON configuration to the console
var iso = $('.grid').data('isotope');
console.log( JSON.stringify( iso.options ) );
console.log( JSON.stringify( iso.options ) );
2018-09-05
Meteor - How to make an HTTP call to Wikipedia's REST API
HTTP.call( 'GET', 'https://en.wikipedia.org/api/rest_v1/page/summary/Jane_Austen', {
params: {
"User-Agent": "your@email.com"
, "Accept": "application/json"
, "charset": "utf-8"
, "profile" : "https://www.mediawiki.org/wiki/Specs/Summary/1.3.7"
}
}, function( error, response ) {
if ( error ) {
console.log( error );
} else {
console.log( response.data );
}
});
params: {
"User-Agent": "your@email.com"
, "Accept": "application/json"
, "charset": "utf-8"
, "profile" : "https://www.mediawiki.org/wiki/Specs/Summary/1.3.7"
}
}, function( error, response ) {
if ( error ) {
console.log( error );
} else {
console.log( response.data );
}
});
2018-08-30
MySQL - How to use a case sensitive regular expression in a where clause
select *
from table_name
where field_name REGEXP '[A-Z]{3,}'
COLLATE utf8_bin
;
from table_name
where field_name REGEXP '[A-Z]{3,}'
COLLATE utf8_bin
;
2018-08-26
Python/MySQL - How to overcome MySQL GROUP_CONCAT character limit
cursor.execute(
'SET SESSION group_concat_max_len = 1000000; \
SELECT a, b, c \
FROM table_name \
WHERE field_name = %s \
;'
, [
variable_for_where_clause
]
, multi=True
)
'SET SESSION group_concat_max_len = 1000000; \
SELECT a, b, c \
FROM table_name \
WHERE field_name = %s \
;'
, [
variable_for_where_clause
]
, multi=True
)
2018-07-24
Inkscape - How to convert a bitmap (PNG, JPG) into an svg
- Open the original bitmap using the following options
- Image import type: Link
- Image DPI: From file
- Image Rendering Mode: Smoot (optimizeQuality)
- Select the bitmap.
- Choose the "Trace bitmap" command from the "Path" menu.
- Choose the following settings (typical for great quality):
- Color: True
- Scans: 5
- Smooth: False
- Stack scans: True
- Remove background: True
- The new trace will be automatically placed over the original bitmap, so click on the image and move it. Then delete the image on the bottom, which represents the original.
- Save. Done.
2018-07-10
MacOS - How to uninstall Google Software Update
sudo /Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/Resources/GoogleSoftwareUpdateAgent.app/Contents/Resources/install.py --nuke
2018-06-05
Bootstrap - How to remove modal's pesky backdrop (gray overlay)
$('#exampleModal2').modal('toggle');
$('#exampleModal2').modal('hide');
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
$('#exampleModal2').modal('hide');
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
2018-05-30
MongoDB - Multiple fields/keys distinct list
db.COLLECTION_NAME.aggregate([
// Filter
{"$match":{
FIELD1 : VALUE1
, FIELD2 : VALUE2
}}
// Distinct fields list
, {"$group": {
"_id": {
FIELD3_ALIAS : "$field3"
, FIELD4_ALIAS :"$field4"
}
}}
// Replace root, so the documents are not nested inside an _id sub-doc
,{ $replaceRoot: {
newRoot: "$_id"
}}
]);//aggregate
// Filter
{"$match":{
FIELD1 : VALUE1
, FIELD2 : VALUE2
}}
// Distinct fields list
, {"$group": {
"_id": {
FIELD3_ALIAS : "$field3"
, FIELD4_ALIAS :"$field4"
}
}}
// Replace root, so the documents are not nested inside an _id sub-doc
,{ $replaceRoot: {
newRoot: "$_id"
}}
]);//aggregate
2018-05-22
2018-05-15
PYTHON - Determine if ANY of the words in a list are found in a given string
wordsList = [ "two", "long" ]
string = "this is a not very long phrase, two would be too many"
if any( word in string for word in wordsList ):
print "yes, all given words are found in the given string"
else:
string = "this is a not very long phrase, two would be too many"
if any( word in string for word in wordsList ):
print "yes, all given words are found in the given string"
else:
print "no, not all given words exist in the given string"
PYTHON - Determine if ALL words in a list are found in a given string
wordsList = [ "two", "long" ]
string = "this is a not very long phrase, two would be too many"
if all( word in string for word in wordsList ):
print "yes, all given words are found in the given string"
else:
print "no, not all given words exist in the given string"
string = "this is a not very long phrase, two would be too many"
if all( word in string for word in wordsList ):
print "yes, all given words are found in the given string"
else:
print "no, not all given words exist in the given string"
2018-05-14
2018-05-05
METEOR - On paste event
Template.template-name-here.events({
'input .class-name-here': function (evt) {}
});
'input .class-name-here': function (evt) {}
});
2018-05-02
2018-04-29
2018-02-18
MongoDB - Query string match in a "like" manner
db.collection_name( { field_name: /search_string/ } );
2018-02-10
MongoDB - Resolve server startup issues
mongod --repair --dbpath /PATH_TO_DB
This resolved this error message:
"Assertion failure isOk() src/mongo/db/storage/mmap_v1/extent.h 81"
This resolved this error message:
"Assertion failure isOk() src/mongo/db/storage/mmap_v1/extent.h 81"
MacOS - Get file or folder absolute path copied to the clipboard
(1) Select a file or folder using Finder
(2) Press COMMAND + OPTION + C
(2) Press COMMAND + OPTION + C
2018-02-09
2018-02-07
MongoDB - Upgrade standalone from v3.4 to v3.6
// Set the feature compatibility version to 3.4
db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } );
db.adminCommand( { setFeatureCompatibilityVersion: "3.4" } )
// Test and let your application season for a while
// Once convinced everything works, then set features compatibility version to 3.6
db.adminCommand( { setFeatureCompatibilityVersion: "3.6" } )
2018-01-06
MongoDB - Aggregation, simple group by single field with frequency count
db.[COLLECTION_NAME].aggregate([
{"$group" : {_id:"$FIELD_TO_GROUP_BY", count:{$sum:1}}}
])
{"$group" : {_id:"$FIELD_TO_GROUP_BY", count:{$sum:1}}}
])
Subscribe to:
Posts (Atom)