Skip to content

Instantly share code, notes, and snippets.

View halilim's full-sized avatar

Halil Özgür halilim

View GitHub Profile
@halilim
halilim / iTerm2 subtitle.md
Created January 4, 2024 11:43
Set iTerm2 subtitle to current git folder or working directory

Put this in shell init scripts (after iterm2_shell_integration):

function iterm2_print_user_vars() {
  iterm2_set_user_var pathShort "$(iterm2_custom_path_short)"
}

function iterm2_custom_path_short() {
  local dir
 dir=$(git rev-parse --show-toplevel 2> /dev/null || pwd)
@halilim
halilim / Homebrew OpenSSH with macOS keychain.md
Created December 29, 2023 20:50
Homebrew OpenSSH with macOS keychain

Problem:

  1. macOS (14.2.1) ssh (OpenSSH_9.4p1, LibreSSL 3.3.6) is vulnerable to Terrapin attack (as reported by the scanner).
  2. The regular OpenSSH (e.g. via Homebrew) doesn't support the UseKeychain option

Workaround:

  1. Automator > new Application > Run Shell Script: ~/bin/login-script, save as Login script.app
  2. Create a new file ~/bin/login-script with contents:
@halilim
halilim / My_Termux_Customizations.md
Last active November 12, 2021 23:42
My Termux customizations. Since I'm not aware of a simpler way of syncing them I just created this. They are mostly subsets of my desktop configs.

Installation

pkg install git vim
git clone https://gist.github.com/6f1c30a51577c2b0370415f210093ba1.git ~/termux_gist
bash ~/termux_gist/setup.sh

# Then, edit `~/.zshrc`:
ZSH_THEME="sunaku"
@halilim
halilim / Chrome_remove_auto_search_engines.js
Last active July 4, 2017 11:58
Remove automatically created search engines from Chrome.
var others = document.querySelectorAll("#other-search-engine-list .deletable-item:not([lead=lead])");
var toBeRemoved = [...others].filter(function(listItem) {
var keyword = listItem.querySelector(".keyword-column .static-text").innerText;
return keyword.includes(".") &&
listItem.querySelector(".url-column .static-text").innerText.toLowerCase().includes(
keyword.toLowerCase()
);
});
if (confirm(`Search engines: \
${document.querySelectorAll("#default-search-engine-list .deletable-item").length} default, \
@halilim
halilim / daily_whois_halil_im.js
Last active May 24, 2017 18:57
Simple AWS Lambda script to notify by SNS if a domain is expiring within 3 days
// Simple AWS Lambda function to notify if the domain halil.im is expiring within 3 days.
// Tested on Node.js 6.10 runtime.
// * Create an SNS topic and an SNS subscription with the email you want to be notified
// * Create the function with a trigger of "CloudWatch Events - Schedule" with rate: 1 day
// * Provide the SNS topic ARN to the function as an environment variable
// * Create and attach a policy to the role of this function with sns:Publish on the SNS topic ARN
// (logs:CreateLogGroup, logs:CreateLogStream & logs:PutLogEvents on a logs ARN should already be there)
/* eslint-env node,es6 */
/* eslint no-console: "off" */
@halilim
halilim / check.md
Last active July 14, 2020 20:49
Text editor color theme test

(Open the files in your editor and try out different color schemes)

It should highlight Markdown headers

It should handle basic styling like inline code, italic text, bold text, but should not italicize_inline under_lined text.

  • A list item
  • Some inline code
  • Etc lorem ipsum
require 'set'
def find_uniq(ids)
# O(n) space
# uniqs = Set.new
# ids.each do |id|
# uniqs.delete(id) unless uniqs.add?(id)
# end
# uniqs.first
# O(1) space
@halilim
halilim / trace_calls.rb
Created March 21, 2016 09:02
A refactoring of TraceCalls (Metaprogramming - Programming Ruby 1.9 & 2.0, 4th edition)
module TraceCalls
def self.included(base)
[base, base.singleton_class].each do |klass|
klass.instance_methods(false).each do |existing_method|
wrap(klass, existing_method)
end
end
def base.method_added(method)
TraceCalls.run_method_added(self, method, __method__)
@halilim
halilim / inheritance_hierarchy.rb
Last active August 20, 2016 18:53
Demonstrating Ruby class/module method inheritance hierarcy
module Extendable # :nodoc:
def self.extended(base)
base.include InstanceMethods
end
module InstanceMethods # :nodoc:
def hello
puts 'hello from Extendable'
super
end
@halilim
halilim / move_heroku_pg_to_aws_rds.md
Last active February 22, 2021 14:13
Move Heroku Postgres to Amazon AWS RDS
  1. Prepare your RDS instance and [authorize access to it][1] (basically make it public).

  2. Put your app in maintenance mode:

    heroku maintenance:on
  3. Save the latest SQL dump of the DB: