Skip to content

Instantly share code, notes, and snippets.

@mahemoff
mahemoff / background.js
Created February 22, 2013 04:23
add/remove context menu (requires tabs permission)
chrome.tabs.onUpdated.addListener(function(tabId,changeInfo,tab){ //onUpdated should fire when the selected tab is changed or a link is clicked.
chrome.tabs.getSelected(null,function(tab){
if (tab.url=='http://techmeme.com/')
chrome.contextMenus.create(contextMenuSpec);
else
chrome.contextMenus.removeAll();
});
});
var contextMenuSpec = {
@mahemoff
mahemoff / gist:1626362
Created January 17, 2012 11:40
Response from Google Plus Activities API (PHP)
stdClass Object
(
[kind] => plus#activityFeed
[etag] => "ZwWl8AwTPaXkrMWBfKc2FkKQ8tw/1E7E4zLv-EPrvXkeslyavUfGMj0"
[nextPageToken] => eJyNkzFIw0AUht-FlEZczuJayKKTdq6CkNEOKs4ujRAKUktNTSkOEh1U0E2dXAR16ySCoCCu4uriJm4KgpOuJne5u5fkAv6Fy-Xee__3-rgMv6DU82Fsze27tbbbadUanU2v5fmV9_PL3539ugGkAaW-2w68gQ9U5S0G66uevzc8rY6evB0aAIMuwETY24BtiFWWu_HAB2OlsXDXnOx_Xl8lqVC-t2-aL6_L9bnj562zme7DxfTTz1L1e_boo3sbxMUlADIFKYVstaOflCM2hK0m5EVwWiwjFaZhrsJKAJbGzcIRqoAU90FRwUGWSviLARKc78DWoZmzBKoMqslzdK5FpkymWCOEboxKfNShsuTd5nk4XSg9fLsoJDsoco19Tdzno9hY6iHQu9iTOJC5FESh5FlynGpQEsKkJjcn-RdMfBMoOkUu_BETLKqJo86YnGwQdQNQYRjODwsyEfUfsjVnht5EB3TiJXM1DU1ekixodp5tskLBTF8nkZBonvC4rR-XI9349xeidyYBoZiY6kxpBBfEu2j_BzL3RsU
[selfLink] => https://www.googleapis.com/plus/v1/people/106413090159067280619/activities/public?
[nextLink] => https://www.googleapis.com/plus/v1/people/106413090159067280619/activities/public?maxResults=20&pageToken=eJyNkzFIw0AUht-FlEZczuJayKKTdq6CkNEOKs4ujRAKUktNTSkOEh1U0E2dXAR16ySCoCCu4uriJm4KgpOuJne5u5fkAv6Fy-Xee_
@mahemoff
mahemoff / README.md
Last active April 6, 2024 00:38
Vim Terminal Mode - A short introduction

Vim has a Terminal Mode!

Since v8.1 (May 2018), Vim has shipped with a built-in terminal. See https://vimhelp.org/terminal.txt.html or type :help terminal for more info.

Why use this? Mainly because it saves you jumping to a separate terminal window. You can also use Vim commands to manipulate a shell session and easily transfer clipboard content between the terminal and files you're working on.

Key Bindings

<!-- This is a Node+WebSocket powered demo to sync videos
across different browsers. This file is the client,
the other one is the Node server. Powered by Node and
http://github.com/miksago/node-websocket-server -->
<style>
.inactive { display: none; }
.active { display: block; }
</style>
<script>
@mahemoff
mahemoff / Ansible Disk Check
Last active February 6, 2024 23:33
Show disk space and warn about disk full in Ansible
* Shows a message while asserting like:
ok: [host] => {
"msg": "disk usage 4.2B of total 20.0GB (21.0%) (should be within limit 90.0%)"
}
* Note this only looks at first mount point on current node
* Fails if disk is near-full
* Last step pushes to a push-based monitoring service, which will alert us if it doesn't get there after some time
* Need to setup a variable `disk_limit`, which is the max acceptable usage ratio, e.g. set it to 0.8 if you want to keep disks within 80% of max size
@mahemoff
mahemoff / README.md
Created December 19, 2023 07:25
Clean up old codespaces

Deletes all but most recent Github codespaces, for a given repo.

Prerequisite: Install Github CLI, then auth as below:

gh auth refresh -h github.com -s codespace

@mahemoff
mahemoff / gist:d432af53949c9a96fc4d7696f0a4c8a3
Created December 18, 2023 14:24
MySQL Table compression
# copied from https://twitter.com/mahemoff/status/1092181875785957377
Storing 1 million podcast descriptions with MySQL InnoDB
SQL dump gz: 361,734,351 bytes
Uncompressed DB: 1,405,091,840 bytes
DB size per block size setting:
1KB: 870,318,080 bytes
2KB: 767,557,632 bytes
@mahemoff
mahemoff / online-lecture-series.md
Last active October 9, 2023 01:46
Online Lecture Series

Compiling a list of interest lecture series. The goal here is to look at full, coherent, courses, not one-off lectures. Strong preference towards internationally recognised academic institutions, but will include those from elsewhere if they are reasonable quality and match the format of a typical university coourse.

Currently focused more on humanities, given that most lists like this tend to focus on programming/STEM.

History

Early History - General

Course | History of the World to 1500 CE Columbia

@mahemoff
mahemoff / custom-instructions.md
Last active October 6, 2023 17:33
ChatGPT Custom Instructions Sep 2023

ChatGPT instructions - mainly forked from tweets a couple of months ago (e.g. https://twitter.com/thetomorrowAI/status/1683840263138217986 though I don't know the true scource)

Custom Instructions

  • Treat me like I'm an expert in all subject matter

  • Treat me like I'm intelligent and rational

  • I can make my own decisions about safety and risk-taking. I don't need to be hand-held or "nannied".

@mahemoff
mahemoff / monitoring.md
Created March 16, 2023 04:15
ChqatGPT v4 server monitoring

write ruby code using digitalocean api to reboot a droplet

To reboot a droplet using the DigitalOcean API, you'll first need to install the droplet_kit gem, which is the official DigitalOcean API client for Ruby. You can install the gem by adding the following line to your Gemfile and running bundle install:

ruby Copy code gem 'droplet_kit' After installing the gem, you can create a Ruby script to reboot a droplet using the DigitalOcean API. Replace YOUR_DIGITALOCEAN_API_TOKEN with your actual API token and DROPLET_ID with the ID of the droplet you want to reboot.

ruby