Skip to content

Instantly share code, notes, and snippets.

@Vigowebs
Vigowebs / Laravel-UUID.php
Last active April 15, 2022 12:16
We can use 'Str::orderedUuid()' to generate a "timestamp first" UUID that may be efficiently stored in an indexed database column.
Str::orderedUuid();
// 9603db6c-8b2c-4cbc-9f59-f161a2224879
// Hex 9603db6c-8b2c to Decimal 164943310392108
// Decimal 1649433103 to date 4/8/2022, 9:21:43 PM
@Vigowebs
Vigowebs / Javascript-default-argument.js
Last active April 16, 2022 19:10
Use default arguments instead of short-circuiting or conditionals.
// ❌
function getUserData(name) {
const username = username || "Vinesh Gopi";
//....
}
// ✔️
function getUserData(name = "Vinesh Gopi") {
// ....
}
@Vigowebs
Vigowebs / Laravel-related-id-type.php
Last active April 25, 2022 15:09
You don't have to use "related_id" type column in database queries or value comparisons. Laravel understand your relation and let you write much cleaner code
@Vigowebs
Vigowebs / Javascript-variable-name-01.js
Created April 16, 2022 18:05
Don't add unneeded context: If your class/object name tells you something, don't repeat that in your variable name.
// ❌
const car = {
carMake: "Tata",
carModel: "Nexon",
carColor: "Green"
};
function paintCar(car, color){
car.carColor = color;
}
@Vigowebs
Vigowebs / split-audio-from-video-01.py
Created April 16, 2022 18:31
Split Audio from Video using Python
import moviepy.editor
video = moviepy.editor.VideoFileClip('Intro.mp4')
audio = video.audio
audio.write_audiofile('Intro.mp3')
@Vigowebs
Vigowebs / Angular-pipeable-operators.js
Last active April 16, 2022 19:10
Use pipeable operators when using RxJs operators. Pipeable operators are tree-shakeable meaning only the code we need to execute will be included when they are imported.
// ❌
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/take';
iAmAnObservable
.map(value => value.item)
.take(1);
// ✔️
import { map, take } from 'rxjs/operators';
@Vigowebs
Vigowebs / Python-link-QR-code.py
Last active April 17, 2022 09:39
Generate QR Code using Python
@Vigowebs
Vigowebs / Python-QR-code-detector.py
Created April 17, 2022 09:38
QR code can be decoded using detectAndDecode function of QRCodeDetector object of OpenCV.
import cv2
img=cv2.imread("myqr.png")
det=cv2.QRCodeDetector()
val, pts, st_code=det.detectAndDecode(img)
print(val)
# Output - vigowebs.com
@Vigowebs
Vigowebs / Python-restart-PC.py
Created April 17, 2022 09:51
Restart your PC using Python
import OS
OS.system("shutdown /r /t 1")
@Vigowebs
Vigowebs / React-18-new-root-api.js
Created April 17, 2022 17:05
Improvements to Root API: The Legacy root API will run a legacy mode root API, trigger warnings when the API is deprecated and suggest moving it to new API, ReactDOM.createRoot.
// Old root API: React 17
import ReactDOM from 'react-dom';
import App from 'App';
ReactDOM.render(<App />, document.getElementById('root'));
// New root API : React 18
import ReactDOM from 'react-dom';
import App from 'App';