Skip to content

Instantly share code, notes, and snippets.

View theHamdiz's full-sized avatar
🎯
Focusing

Ahmad Hamdi theHamdiz

🎯
Focusing
View GitHub Profile
@theHamdiz
theHamdiz / main.dart
Created December 25, 2023 09:16
Generated code from pixels2flutter.dev
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
@theHamdiz
theHamdiz / simple_clock_app_in_js.js
Created March 31, 2018 23:01
a digital clock app that refreshes itself every second.
button = document.getElementById('start');
button.onclick = show;
function show(){
document.body.innerHTML = Date();
setInterval(show, 1000);
}
@theHamdiz
theHamdiz / copy_cat_input_to_div.js
Created March 31, 2018 23:00
copy the exact text of input to a div on change in js
function change(){
var show_div = document.getElementById("show_div");
var i = document.getElementById("i");
show_div.innerHTML = i.value.toUpperCase();
}
@theHamdiz
theHamdiz / dynamic_event_listener.js
Created March 31, 2018 22:59
Add dynamic event listener and remove it on the fly in js.
var dynamic = document.getElementById('dynamic');
dynamic.addEventListener('click', dynamic_click);
function dynamic_click() {
alert(Math.random());
dynamic.removeEventListener('click', dynamic_click);
}
@theHamdiz
theHamdiz / quran_suggest.rb
Last active February 20, 2018 06:53
كود روبي بسيط يقوم باقتراح وفتح صفحه من القرآن عشوائيه لك لقرائتها. #Ruby script to suggest a page from the #Quran to read and open it. This base script could be further twisted to select a random #book for you to read and actually open it for you. or any other paged book that you have its pages available in your hard drive or on the internet.
class Quran
def initialize
# could be ARGV OR Any other path you prefer
@path = '/Users/a7madx7/Downloads/المصحف\ الجوامعي'
end
private
def suggest
# related to the quran could be changed
# ☺
puts ""
name = gets.chomp
puts "Welcome, #{name}"
class Player
attr_accessor :name, :health, :power
def initialize(n, h, pow)
@name = n
@health = h
@power = pow
# Parts of Patterns
s0, s1, s2, s3, s4, s5 = " o ", " ", " - ", "| ", " |", "| |"
# Patterns of Numbers
n = {
":" => [s1, s0, s1, s0, s1],
"0" => [s2, s5, s1, s5, s2],
"1" => [s1, s4, s1, s4, s1],
"2" => [s2, s4, s2, s3, s2],
"3" => [s2, s4, s2, s4, s2],
@theHamdiz
theHamdiz / Letter frequency calculator.rb
Created December 24, 2017 20:04
Ruby script to calculate the frequency of appearance of specific characters in a text, as well as mentioning the letters that were excluded by the author
puts 'Provide the sentence you want to perform letter frequency on'
text = gets.chomp # gets the sentence to iterate
puts "Performing on: #{text[0..6]}..."
text.downcase!
freqs = {} # creating a hash to iterate 'text'
freqs.default = 0
count = 0 # number of charachters in 'text'
# iterating through text
text.each_char do |char|
@theHamdiz
theHamdiz / my_next_birthdays.rb
Created July 8, 2017 05:14
Get to know your next 'n' number of birthdays including the name of the day its occurring on.
require 'date'
def my_next_n_birthdays(number_of_years = 60, birthday = 24, birth_month = 8)
lazy_dates = (Date.today..Date.new(9999)).lazy
my_next_birthdays = lazy_dates.select { |d| d.day == birthday and d.month == birth_month }.first(number_of_years).map { |date| "#{date.strftime('%A')} - #{date}"}
end
puts my_next_n_birthdays
@theHamdiz
theHamdiz / selection_sort.rb
Last active June 12, 2017 07:06
Best way to perform selection sorting in ruby, a not so recommended algorithm for large sets of data.
require_relative 'random_password'
include RandomPassword
class Array
def selection_sort
start_time = Time.now
# Selection sort (very slow on large lists)
a = self
# get the number of indices in the array
n = a.size - 1