Skip to content

Instantly share code, notes, and snippets.

View theanam's full-sized avatar
One coffee every five minute.

Anam Ahmed theanam

One coffee every five minute.
View GitHub Profile
@theanam
theanam / crux1_start_gcode_kp3s.gcode
Created November 24, 2022 21:07
Crux 1 start Gcode if you are using kp3s profile
; start heating up the bed and nozzle together
M140 S{material_bed_temperature_layer_0} ; Set bed temperature
M104 S{material_print_temperature_layer_0} T0 ; Set nozzle temp
G28 ; home all axes
M190 S{material_bed_temperature_layer_0} ; Set bed temperature and wait
M109 S{material_print_temperature_layer_0} T0 ; Set nozzle temp and wait
M117 Purge extruder
G92 E0 ; reset extruder
G1 Z5.0 F3000 ; move z up little to prevent scratching of surface
G1 X5 Y20 Z0.3 F5000.0 ; move to start-line position
@theanam
theanam / crux1_start.gcode
Last active September 16, 2023 06:10
Tronxy Crux 1 Start G-Code for cura
; Tronxy Crux1 Start Code
; Forked from the Tronxy XY 2 Pro Start code on cura
; Improvement: Start nozzle and bed heating together
; Imorovement: Fixed purge line (XY2 version was for a bigger bed and would draw out of build area)
; Bugfix: On glass bed Crux 1, the nozzle would bump on the retainer trying to draw the purge line. Fixed in this version.
; Cleanup: Removed all ABL related code since Crux 1 does not have ABL.
G21 ; Set units to millimeters
G90 ; Set all axis to Absolute
M82 ; Set extrusion to Absolute
M107 ; Disable all fans
@theanam
theanam / checkRTC.js
Last active June 5, 2020 19:14
Check if user's network supports WebRTC transport by probing a webRTC data channel. Why? because despite having feature support in browser. It might fail because of network or a faulty/unsupported rtcConfig.
/**
* Created By Anam Ahmed (https://anam.co)
* Test the browser's capability to establish RTCPeerConnection with supplied RTC Configuration
* How to use: probeRTC(RTCParam,false, callback) // will call callback function with true or false.
* If you don't supply the callback function it will return a Promise.
* The promise will resolve (with total time required for the whole round trip ,in ms) or reject (with error) based on the result.
* Setting verbose = true will print logs in console
* @param {RTCConfiguration} rtcConfig
* @param {Boolean} verbose
* @param {Function} callback [optional]
@theanam
theanam / otpverify.js
Last active March 31, 2024 17:05
OTP verification without database, full sample source code
const otpGenerator = require("otp-generator");
const crypto = require("crypto");
const key = "verysecretkey"; // Key for cryptograpy. Keep it secret
function createNewOTP(phone){
// Generate a 6 digit numeric OTP
const otp = otpGenerator.generate(6, {alphabets: false, upperCase: false, specialChars: false});
const ttl = 5 * 60 * 1000; //5 Minutes in miliseconds
const expires = Date.now() + ttl; //timestamp to 5 minutes in the future
const data = `${phone}.${otp}.${expires}`; // phone.otp.expiry_timestamp
@theanam
theanam / verifyhash.js
Last active October 3, 2019 05:27
Verify hash
// These imports and values are the same from the create source code. Perhaps you should keep them in the same file
// For the sake of demonstration, the imports are used here as well.
const crypto = require("crypto");
const key = "verysecretkey"; // Key for cryptograpy. Keep it secret
function verifyOTP(phone,hash,otp){
// Seperate Hash value and expires from the hash returned from the user
let [hashValue,expires] = hash.split(".");
// Check if expiry time has passed
let now = Date.now();
@theanam
theanam / sendhash.js
Last active January 18, 2024 15:52
create SMS OTP hash
const otpGenerator = require("otp-generator");
const crypto = require("crypto");
const key = "verysecretkey"; // Key for cryptograpy. Keep it secret
function createNewOTP(phone){
// Generate a 6 digit numeric OTP
const otp = otpGenerator.generate(6, {alphabets: false, upperCase: false, specialChars: false});
const ttl = 5 * 60 * 1000; //5 Minutes in miliseconds
const expires = Date.now() + ttl; //timestamp to 5 minutes in the future
const data = `${phone}.${otp}.${expires}`; // phone.otp.expiry_timestamp
@theanam
theanam / docker-compose.yml
Created September 22, 2019 13:11
Docker Compose for Simple WordPress
version: "3"
services:
# Wordpress
mysite:
image: wordpress:5.2.3-php7.1-apache
volumes:
- ./themes:/var/www/html/wp-content/themes
- ./plugins:/var/www/html/wp-content/plugins
ports:
@theanam
theanam / regex.txt
Created September 4, 2019 10:08
Regular Expression to match Bangladeshi Phone number
/^(?:\+88|88)?(01[3-9]\d{8})$/
@theanam
theanam / resize_image_in_frontend.js
Last active September 21, 2021 05:03
A small JavaScipt function to resize image in frontend and return a new JPEG file
/****
Creatd by Anam Ahmed (https://anam.co)
Sample Use:
document.querySelector("input[type=file]").addEventListener("change",function(e){
if(e.target.files.length){
_resample(e.target.files[0],1000,function(response){
console.log(response); // returns an object: {stats:<compression stats>,file:output file}
});
}
});
@theanam
theanam / logger.js
Created April 5, 2019 17:53
Stdout logs on Steroids
const moment = require('moment');
const colors = {
"green" :"\x1b[32m",
"yellow":"\x1b[33m%s\x1b[0m",
"red":"\x1b[31m",
"cyan":"\x1b[36m",
"blue":"\x1b[34m",
"default":""
}
module.exports = function (message,color="default"){