Skip to content

Instantly share code, notes, and snippets.

View BytesCrafter's full-sized avatar
🖥️
Software Development Services

BytesCrafter BytesCrafter

🖥️
Software Development Services
View GitHub Profile
@BytesCrafter
BytesCrafter / mysql-
Created September 10, 2023 14:21
MYSQL USEFULL BUT DANGEROUS COMMANDS
# Update all email address in a users table to a specific domain name
UPDATE users
SET email = CONCAT(LEFT(email, INSTR(email, '@')), 'example.com')
@BytesCrafter
BytesCrafter / gist:88467b22b2782c5c4d3c8758b6b23f40
Created January 10, 2023 20:05
Check if time is in between PHP
$current = get_my_local_time('h:i a');
$sunrise = "8:00 am";
$sunset = "5:00 pm";
$date1 = DateTime::createFromFormat('h:i a', $current);
$date2 = DateTime::createFromFormat('h:i a', $sunrise);
$date3 = DateTime::createFromFormat('h:i a', $sunset);
if ($date1 > $date2 && $date1 < $date3) {
echo 'enabled';
} else {
echo "disabled";
$NumberOfLogicalProcessors = Get-WmiObject win32_processor | Select-Object -ExpandProperty NumberOfLogicalProcessors
ForEach ($core in 1..$NumberOfLogicalProcessors){
start-job -ScriptBlock{
$result = 1;
foreach ($loopnumber in 1..2147483647){
$result=1;
################################
gource commands
################################
# basic command for big and long projects
gource --max-user-speed 500 --seconds-per-day 0.05 --file-idle-time 10 -e 0.005 -f --max-files 300 --hide-files
# some easy to understand commands
# for output file
--output-ppm-stream ~/ppm/ppm-kohana
@BytesCrafter
BytesCrafter / gist:4e8aecf5480ad04be61c83bf8d97ea58
Created July 22, 2020 10:01
Sample RestAPI client on Xamarin
using Newtonsoft.Json;
using PasaBuy.App.Controllers.Notice;
using PasaBuy.App.Models.Onboarding;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http;
namespace XamarinNet
{
function dbhook_activate() {
global $wpdb;
// #region CREATING TABLE FOR Clusters
$usn_cluster_tab = USN_CLUSTER_TAB;
if($wpdb->get_var( "SHOW TABLES LIKE '$usn_cluster_tab'" ) != $usn_cluster_tab) {
$sql = "CREATE TABLE `".$usn_cluster_tab."` (";
$sql .= "`ID` bigint(20) NOT NULL AUTO_INCREMENT, ";
$sql .= "`cluster_name` varchar(120) NOT NULL, ";
$sql .= "`cluster_info` varchar(255) NOT NULL, ";
using System.Net.Http;
using System.Net.Http.Headers;
using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace BytesCrafter.Xamarin
{
@BytesCrafter
BytesCrafter / nodejs-cpu-percent.js
Created April 28, 2020 06:36
Convert the output of os.cpus() in Node.js to percentage
// According to the http://nodejs.org/docs/latest/api/os.html#os_os_cpus, times is
// an object containing the number of CPU ticks spent in: user, nice, sys, idle, and irq
// So you should just be able to sum the times and calculate the percentage, like below:
var cpus = os.cpus();
for(var i = 0, len = cpus.length; i < len; i++) {
console.log("CPU %s:", i);
var cpu = cpus[i], total = 0;