Skip to content

Instantly share code, notes, and snippets.

View shamsher31's full-sized avatar
🎯
Focusing

Shamsher Ansari shamsher31

🎯
Focusing
View GitHub Profile
@shamsher31
shamsher31 / check_gpu.py
Created June 4, 2024 11:19
The simplest way to identify if you system has a dedicated GPU
# Install GPUtil
pip install gputil
# Create a Python script (e.g., check_gpu.py)
import GPUtil
try:
gpus = GPUtil.getAvailable(order='first', limit=8, maxLoad=0.5, maxMemory=0.5)
if gpus:
$ cat ~/.crc/crc.log
time="2021-07-16T15:42:49+05:30" level=debug msg="CodeReady Containers version: 1.29.1+bc5f4409\n"
time="2021-07-16T15:42:49+05:30" level=debug msg="OpenShift version: 4.7.18 (embedded in executable)\n"
time="2021-07-16T15:42:49+05:30" level=debug msg="Running 'crc setup'"
time="2021-07-16T15:42:49+05:30" level=debug msg="Checking if systemd-resolved.service is running"
time="2021-07-16T15:42:49+05:30" level=debug msg="Running 'systemctl status systemd-resolved.service'"
time="2021-07-16T15:42:49+05:30" level=debug msg="Command failed: exit status 3"
time="2021-07-16T15:42:49+05:30" level=debug msg="stdout: * systemd-resolved.service - Network Name Resolution\n Loaded: loaded (/usr/lib/systemd/system/systemd-resolved.service; disabled; vendor preset: disabled)\n Active: inactive (dead)\n Docs: man:systemd-resolved.service(8)\n https://www.freedesktop.org/wiki/Software/systemd/resolved\n https://www.freedesktop.org/wiki/Software/systemd/writing-network-configur
$ cat ~/.crc/crc.log
time="2021-07-16T14:08:36+05:30" level=debug msg="CodeReady Containers version: 1.29.1+bc5f4409\n"
time="2021-07-16T14:08:36+05:30" level=debug msg="OpenShift version: 4.7.18 (embedded in executable)\n"
time="2021-07-16T14:08:36+05:30" level=debug msg="Running 'crc version'"
time="2021-07-16T14:08:38+05:30" level=debug msg="No new version available. The latest version is 1.29.1"
time="2021-07-16T14:08:44+05:30" level=debug msg="CodeReady Containers version: 1.29.1+bc5f4409\n"
time="2021-07-16T14:08:44+05:30" level=debug msg="OpenShift version: 4.7.18 (embedded in executable)\n"
time="2021-07-16T14:08:44+05:30" level=debug msg="Running 'crc setup'"
time="2021-07-16T14:08:49+05:30" level=debug msg="Checking if systemd-resolved.service is running"
time="2021-07-16T14:08:49+05:30" level=debug msg="Running 'systemctl status systemd-resolved.service'"
Verifying my Blockstack ID is secured with the address 1NLJD3ZMNrkAgDsLSvhzQpK1FsGsVULKX4 https://explorer.blockstack.org/address/1NLJD3ZMNrkAgDsLSvhzQpK1FsGsVULKX4
@shamsher31
shamsher31 / Find element in nested array of objects
Created April 5, 2017 05:30
Find element in nested array of objects
function getMenuById(menu, id) {
if (menu.name == id){
return menu;
}
if (menu.children) {
for (let key in menu.children) {
// console.log(menu.id, ' : ', menu.children[key].name);
if (menu.children[key].name === id) {
return menu.children[key];
}
@shamsher31
shamsher31 / Flatten Nested Array of Objects.
Created March 30, 2017 10:22
Flatten Nested Array of Objects.
// Example http://stackoverflow.com/questions/30916031/lodash-deepflatten-array-of-objects
function getPeople(persons){
var result = [];
_.each(persons, function(person){
result.push({name: person.name, age: person.age});
person.children && (result = _.union(result,getPeople(person.children)))
});
return result
}
@shamsher31
shamsher31 / golang-encrypt-decrypt.go
Last active December 1, 2023 12:22
Golang Encrypt Decrypt
// Refrence http://stackoverflow.com/questions/18817336/golang-encrypting-a-string-with-aes-and-base64
package main
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/base64"
"errors"
"fmt"
@shamsher31
shamsher31 / Toggel Class
Created March 8, 2016 05:59
Angular Toggel Class
// Ref: http://stackoverflow.com/questions/25141139/toggle-class-with-ng-click-on-several-elements
module.directive('toggleClass', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('click', function() {
element.toggleClass(attrs.toggleClass);
});
}
};
@shamsher31
shamsher31 / Angular Draggable Container
Created January 8, 2016 12:47
Angular Draggable Container
.directive('draggable', function($document) {
return function(scope, element, attr) {
var startX = 0, startY = 0, x = 0, y = 0;
element.on('mousedown', function(event) {
// Prevent default dragging of selected content
event.preventDefault();
startX = event.screenX - x;
startY = event.screenY - y;
$document.on('mousemove', mousemove);
$document.on('mouseup', mouseup);
@shamsher31
shamsher31 / Export to Excel with multiple sheet
Created October 16, 2015 10:13
Export to Excel with multiple sheet
var excelbuilder = require('msexcel-builder');
// Create a new workbook file in current working-path
var workbook = excelbuilder.createWorkbook('./', 'sample.xlsx')
// Create a new worksheet with 10 columns and 12 rows
var sheet1 = workbook.createSheet('sheet1', 10, 12);
var sheet2 = workbook.createSheet('sheet2', 10, 12);
var sheet3 = workbook.createSheet('sheet3', 10, 12);