Skip to content

Instantly share code, notes, and snippets.

@emad-elsaid
emad-elsaid / ago.go
Last active June 19, 2022 23:02
Converts a time duration to string. for example: 38 minutes 53 seconds ago OR 2 days 58 minutes ago. maxPrecision is the max number of time components in the result.
func ago(t time.Duration) (o string) {
const day = time.Hour * 24
const week = day * 7
const month = day * 30
const year = day * 365
const maxPrecision = 2
if t.Seconds() < 1 {
return "seconds ago"
}
This is a list of ways to say hello in various languages.
It is not intended to be comprehensive, but to demonstrate
some of the character sets that Emacs supports.
Non-ASCII examples:
Europe: ¡Hola!, Grüß Gott, Hyvää päivää, Tere õhtust, Bonġu
Cześć!, Dobrý den, Здравствуйте!, Γειά σας, გამარჯობა
Africa: ሠላም
Middle/Near East: שָׁלוֹם, السّلام عليكم
South Asia: નમસ્તે, नमस्ते, ನಮಸ್ಕಾರ, നമസ്കാരം, ଶୁଣିବେ,
@emad-elsaid
emad-elsaid / gtk.go
Created March 4, 2021 21:19
this will load a UI/glade file using GTK builder and will bind objects from the UI to a go struct using the struct field tag as an ID
package main
import (
"fmt"
"log"
"reflect"
"github.com/gotk3/gotk3/gtk"
)
@emad-elsaid
emad-elsaid / explain.rb
Created December 10, 2020 08:47
rails_explain_sql_initializer
class Explainer < ActiveSupport::LogSubscriber
def sql(event)
payload = event.payload
return if ignore_payload?(payload)
debug color(ActiveRecord::Base.connection.explain(payload[:sql], payload[:binds]), :yellow)
end
private
@emad-elsaid
emad-elsaid / web-history.sh
Last active October 12, 2020 16:07
This will read your google chrome local history database and offer you fuzzy search with dmenu to open one of them
#!/usr/bin/env bash
cp ~/.config/google-chrome/Default/History /tmp/History
sqlite3 /tmp/History "select url, title from urls;" \
| dmenu -i -l 20 -fn "Source Code Pro:regular:size=16" \
| awk 'BEGIN { FS = "|" } ; { print $1 }' \
| xargs xdg-open
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'bundler/inline'
require 'fileutils'
gemfile do
source 'https://rubygems.org'
gem 'gtk3'
end
@emad-elsaid
emad-elsaid / index.html
Created July 15, 2020 06:22
WebRTC Chat server using simple-peer and Inbox server
<html>
<body>
<form id="userform">
<label>Username</label>
<input id="username" type="text">
<label>Password</label>
<input id="password" type="password">
<label>Other peer Username (only if your the initiator)</label>
<input id="to" type="text">
<button onclick="CreateUser()" type="button">Create</button>
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Tricks {
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
}
"@
while($TRUE)

the bash_profile snippet will let you run the first file when you press tab when you have empty command , you need to put the cmd file in your path and make it executable with chmod +x cmd

class ThreadPool
def self.execute(objects:, method:, pool: 5)
new(objects: objects, method: method, pool: pool).execute
end
def initialize(objects:, method:, pool:)
@objects = objects
@method = method
@pool = pool
@queue = queue