Posts

Showing posts from May, 2004

Aws-sdk S3: Best Way To List All Keys With ListObjectsV2

Answer : this is the best way to do that in my opinion: const AWS = require('aws-sdk'); const s3 = new AWS.S3(); const listAllKeys = (params, out = []) => new Promise((resolve, reject) => { s3.listObjectsV2(params).promise() .then(({Contents, IsTruncated, NextContinuationToken}) => { out.push(...Contents); !IsTruncated ? resolve(out) : resolve(listAllKeys(Object.assign(params, {ContinuationToken: NextContinuationToken}), out)); }) .catch(reject); }); listAllKeys({Bucket: 'bucket-name'}) .then(console.log) .catch(console.log); Here is the code to get the list of keys from a bucket. var params = { Bucket: 'bucket-name' }; var allKeys = []; listAllKeys(); function listAllKeys() { s3.listObjectsV2(params, function (err, data) { if (err) { console.log(err, err.stack); // an error occurred } else { var contents = data.Contents; contents.forEach(function (c

Youtube 2 Mp3 Code Example

Example 1: youtube-dl mp3 only youtube - dl - x -- audio - format mp3 < youtube - link > Example 2: youtube mp3 converter You can use WebTools , it's an addon that gather the most useful and basic tools such as a synonym dictionary , a dictionary , a translator , a youtube convertor , a speedtest and many others ( there are ten of them ) . You can access them in two clics , without having to open a new tab and without having to search for them ! - Chrome Link : https : //chrome.google.com/webstore/detail/webtools/ejnboneedfadhjddmbckhflmpnlcomge/ Firefox link : https : //addons.mozilla.org/fr/firefox/addon/webtools/ Example 3: youtube to mp4 ytmp3 . cc is the best by far Example 4: youtube download mp3 I use https : //github.com/ytdl-org/youtube-dl/ as a Python CLI tool to download videos Example 5: youtube to mp3 online This man is doing gods work

BodyParser Is Deprecated Express 4

Answer : It means that using the bodyParser() constructor has been deprecated, as of 2014-06-19. app.use(bodyParser()); //Now deprecated You now need to call the methods separately app.use(bodyParser.urlencoded()); app.use(bodyParser.json()); And so on. If you're still getting a warning with urlencoded you need to use app.use(bodyParser.urlencoded({ extended: true })); The extended config object key now needs to be explicitly passed, since it now has no default value. If you are using Express >= 4.16.0, body parser has been re-added under the methods express.json() and express.urlencoded() . Want zero warnings ? Use it like this: app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); Explanation : The default value of the extended option has been deprecated, meaning you need to explicitly pass true or false value. If you're using express > 4.16 , you can use express.json() and express.urlencoded() The expres

Codeigniter Active Record Left Join

Answer : You have wrong where clause you need to compare user_id from your table ,you are comparing the id of email to the provided $user_id $CI->db->select('email'); $CI->db->from('emails'); $CI->db->where('user_id', $userid); $CI->db->join('user_email', 'user_email.user_id = emails.id', 'left'); $query = $CI->db->get(); A more useful way is to give aliases to your tables so the tables with same columns will not have any confusion $CI->db->select('e.email'); $CI->db->from('emails e'); $CI->db->join('user_email ue', 'ue.user_id = e.id', 'left'); $CI->db->where('ue.user_id', $userid); $query = $CI->db->get();

Android - Black Status Bar Icon On Marshmallow Making It Unreadable On Dark Wallpaper

Answer : Based on reddit (and I have tested it myself), apparently it's a feature of Nova Launcher on Android 6.0 Marshmallow called "Dark icons". It seems it's enabled by default for existing users after updating the app (on my case, new installation will have to turn this setting on manually). The setting can be checked on Nova Settings - Look & feel - Dark icons . Note that this is a new feature of Marshmallow, allowing an app to have black status icons for light status bar, and thus, the setting is only available on Marshmallow and above. As for why it also affected Google Now Launcher, I actually have no idea, since I couldn't reproduce the issue on Nexus 5 running Marshmallow 6.0. Even if I leave the option enabled on Nova Launcher, changing the home setting (on Settings - Home - Google Now Launcher ) and pressing "Home" button will revert the whole launcher to Google Now Launcher with its default white icon.

AttributeError: Module 'datetime' Has No Attribute 'striptime' Code Example

Example: module 'datetime' has no attribute 'strptime' Use this: from datetime import datetime instead of Import datetime

Android Fragment Life Cycle Code Example

Example: fragment lifecycle onAttach()The fragment instance is associated with an activity instance.The fragment and the activity is not fully initialized. Typically you get in this method a reference to the activity which uses the fragment for further initialization work. onCreate() The system calls this method when creating the fragment. You should initialize essential components of the fragment that you want to retain when the fragment is paused or stopped, then resumed. onCreateView() The system calls this callback when it's time for the fragment to draw its user interface for the first time. To draw a UI for your fragment, you must return a View component from this method that is the root of your fragment's layout. You can return null if the fragment does not provide a UI. onActivityCreated()The onActivityCreated() is called after the onCreateView() method when the host activity is created. Activity and fragment instance have been created as well as the view hierarc

Canvas Border Color Tkinter Code Example

Example 1: tkinter text in canvas self . canvas = Canvas ( root , width = 800 , height = 650 , bg = '#afeeee' ) self . canvas . create_text ( 100 , 10 , fill = "darkblue" , font = "Times 20 italic bold" , text = "Click the bubbles that are multiples of two." ) Example 2: canvas.create_oval parameters id = C . create_oval ( x0 , y0 , x1 , y1 , option , . . . )

Can A $text Search Perform A Partial Match

Answer : MongoDB $text searches do not support partial matching. MongoDB allows text search queries on string content with support for case insensitivity, delimiters, stop words and stemming. And the terms in your search string are, by default, OR'ed. Taking your (very useful :) examples one by one: SINGLE TERM, PARTIAL // returns nothing because there is no world word with the value `Crai` in your // text index and there is no whole word for which `Crai` is a recognised stem db.submissions.find({"$text":{"$search":"\"Crai\""}}) MULTIPLE TERMS, COMPLETE // returns the document because it contains all of these words // note in the text index Dr. Bob is not a single entry since "." is a delimiter db.submissions.find({"$text":{"$search":"\"Craig\" \"Dr. Bob\""}}) MULTIPLE TERMS, ONE PARTIAL // returns the document because it contains the whole word "Craig" an

26 Inch To Cm Code Example

Example: inch to cm 1 inch = 2.54 cm

Colspan In Bootstrap Grid Code Example

Example: bootstrap grid 2 rows < link href = " https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css " rel = " stylesheet " /> < div class = " row " > < div class = " col-md-4 " > < div class = " well " > 1 < br /> < br /> < br /> < br /> < br /> </ div > </ div > < div class = " col-md-8 " > < div class = " row " > < div class = " col-md-6 " > < div class = " well " > 2 </ div > </ div > < div class = " col-md-6 " > < div class = " well " > 3 </ div > </ div > </ div > < div class = " row " >

Add Primary Key To Existing Table Oracle Code Example

Example 1: add primary key constraint in oracle -- Adding Using alter ALTER TABLE table_name ADD CONSTRAINT constraint_name PRIMARY KEY ( column1 , column2 , . . . column_n ) ; Example 2: drop primary key oracle -- Dropping Using alter ALTER TABLE table_name DROP CONSTRAINT constraint_name ;

Angular.js Cdn Code Example

Example 1: angularjs cdn <! doctype html > < html ng-app > < head > < title > My AngularJS App </ title > < script src = " https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js " > </ script > </ head > < body > </ body > </ html > Example 2: angular.min.js version < script src = " https://ajax.googleapis.com/ajax/libs/angularjs/1.7.9/angular.min.js " > </ script >

Bcrypt Password Online Code Example

Example 1: bcrypt create encrypted password bcrypt.hash(password, 12).then(hash => { console.log(hash) }); Example 2: bcrypt >>> import bcrypt >>> password = b"super secret password" >>> # Hash a password for the first time, with a randomly-generated salt >>> hashed = bcrypt.hashpw(password, bcrypt.gensalt()) >>> # Check that an unhashed password matches one that has previously been >>> # hashed >>> if bcrypt.checkpw(password, hashed): ... print("It Matches!") ... else: ... print("It Does not Match :(")

Angular FormatDate

function Formats a date according to locale rules. formatDate(value: string | number | Date, format: string, locale: string, timezone?: string): string Parameters value string | number | Date The date to format, as a Date, or a number (milliseconds since UTC epoch) or an ISO date-time string. format string The date-time components to include. See DatePipe for details. locale string A locale code for the locale format rules to use. timezone string The time zone. A time zone offset from GMT (such as '+0430' ), or a standard UTC/GMT or continental US time zone abbreviation. If not specified, uses host system settings. Optional. Default is undefined . Returns string : The formatted date string. See also DatePipe Internationalization (i18n) Guide

Determine Array Size Python Code Example

Example 1: size array python size = len ( myList ) Example 2: python get array length # To get the length of a Python array , use 'len()' a = arr . array ( ‘d’ , [ 1.1 , 2.1 , 3.1 ] ) len ( a ) # Output : 3

C++ Cannot Get Value Of Double Pointr Code Example

Example: double pointers C++ # include <stdio.h> int main ( void ) { int value = 100 ; int * value_ptr = & value ; int * * value_double_ptr = & value_ptr ; printf ( "Value: %d\n" , value ) ; printf ( "Pointer to value: %d\n" , * value_ptr ) ; printf ( "Double pointer to value: %d\n" , * * value_double_ptr ) ; }

Android How Do I Correctly Get The Value From A Switch?

Answer : Switch s = (Switch) findViewById(R.id.SwitchID); if (s != null) { s.setOnCheckedChangeListener(this); } /* ... */ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Toast.makeText(this, "The Switch is " + (isChecked ? "on" : "off"), Toast.LENGTH_SHORT).show(); if(isChecked) { //do stuff when Switch is ON } else { //do stuff when Switch if OFF } } Hint: isChecked is the new switch value [ true or false ] not the old one. Since it extends from CompoundButton (docs), you can use setOnCheckedChangeListener() to listen for changes; use isChecked() to get the current state of the button. Switch switch = (Switch) findViewById(R.id.Switch2); switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) {

CloudFormation Is Not Authorized To Perform: Iam:PassRole On Resource

Answer : While I can't say specifically what happened in your situation, the error message means that the Role/User that CloudFormation used to deploy resources did not have appropriate iam:PassRole permissions. The iam:PassRole permission is used when assigning a role to resources. For example, when an Amazon EC2 instance is launched with an IAM Role, the entity launching the instance requires permission to specify the IAM Role to be used. This is done to prevent users gaining too much permission . For example, a non-administrative user should not be allowed to launch an instance with an Administrative role, since they would then gain access to additional permissions to which they are not entitled. In the case of your template, it would appear that CloudFormation is creating a function and is assigning the FnRole permission to that function. However, the CloudFormation template has not been given permission to assign this role to the function . When a CloudFormation te

Alter Column Sql Server Code Example

Example 1: sql change column types ALTER TABLE table_name ALTER COLUMN column_name datatype; -- Example ALTER TABLE product ALTER COLUMN description VARCHAR(250); Example 2: sql add column ALTER TABLE Customers ADD Email varchar(255); Example 3: sql server alter column ALTER TABLE table_name ALTER COLUMN column_name new_data_type(size); Example 4: alter table add column ALTER TABLE table ADD COLUMN column VARCHAR (255) NOT NULL AFTER column; Example 5: sqlserver add column to table ALTER TABLE dbo.doc_exa ADD column_b VARCHAR(20) NULL, column_c INT NULL ; Example 6: alter column sql server ALTER TABLE table_name ALTER COLUMN column_name datatype;