Skip to content

Instantly share code, notes, and snippets.

@afiram
afiram / source_bash.fish
Last active December 4, 2022 03:21
source_bash in fish
# load environment variables like bash, dotenv
# from https://github.com/edc/bass
function source_bash
# echo $argv
# exec bash -c "set -a;. $argv;fish"
exec bash -c "set -a;. $argv;fish -C 'function fish_greeting;end'"
end
@afiram
afiram / ExportKindle.js
Last active January 9, 2022 08:20 — forked from jkubecki/ExportKindle.js
Amazon Kindle Export
// The following data should be run in the console while viewing the page https://read.amazon.com/
// It will export a CSV file called "download" which can (and should) be renamed with a .csv extension
// var db = openDatabase('K4W', '3', 'thedatabase', 1024 * 1024);
var db = openDatabase('K4W', '5', 'thedatabase', 1024 * 1024);
getAmazonCsv = function() {
// Set header for CSV export line - change this if you change the fields used
var csvData = "ASIN,Title,Authors,PurchaseDate\n";
@afiram
afiram / gist-spam-attack-log.txt
Last active November 30, 2021 01:44
gist spam attack log
(edited) this is log.
When I posted the UserScript, there was a spam attack within three minutes.
spam is
- https://gist.github.com/afiram/2a4818d4704283dde579d0dcbca8c671#gistcomment-3978299
- virustotal report https://www.virustotal.com/gui/url/ec6718af396f8dc11a362d7000618ed9c6de994795d9510a4d2efedc666d4728?nocache=1

Implement the Least Recently Used (LRU) cache class:

  • LRUCache(int capacity) Initialize the LRU cache with positive size capacity.
  • get(key) Return the value of the key if the key exists, otherwise return -1.
  • void put(key, value) Update the value of the key if the key exists. Otherwise, add the key-value pair to the cache.
  • If the number of keys exceeds the capacity from this operation, evict old key.
  • Follow up: Could you do get and put in O(1) time complexity?

Example 1:

@afiram
afiram / problem-remove-comments.md
Last active December 4, 2022 03:25
problem-remove-comments

Remove Comments

  • Given a C++ program, remove comments ("// foo", /* foo */") from it.
  • there is no nested comment
  • input is string array. not file.

Example 1:

// Input: 
@afiram
afiram / code-notranslate.user.js
Created June 27, 2019 11:47
code notranslate css in google translater
// ==UserScript==
// @name code-notranslate.user.js
// @description code notranslate css in google translater
// @match *://*/*
// ==/UserScript==
["pre", "code",".highlight"].map(x=>[].map.call(document.querySelectorAll(x),e =>
e.classList.add("notranslate")))
// ==UserScript==
// @name slack-archives-fast-open-in-app.user.js
// @namespace Violentmonkey Scripts
// @match https://*.slack.com/archives/*
// @grant none
// ==/UserScript==
window.addEventListener('load', function() {
window.location=link
})
// ==UserScript==
// @name slack archives fast open in browser userjs
// @namespace Violentmonkey Scripts
// @match https://*.slack.com/archives/*
// @grant none
// ==/UserScript==
window.addEventListener('load', function() {
document.querySelector('.fallback a').click()
})
@afiram
afiram / excepthook.py
Last active February 27, 2018 10:39
python sys.excepthook
import sys
def excepthook(type, value, tb):
import sys, traceback
traceback.print_exception(type, value, tb)
while tb.tb_next:
tb = tb.tb_next
# print('Globals:', tb.tb_frame.f_globals)
for k,v in tb.tb_frame.f_locals.items():
fv = str(v)
@afiram
afiram / settings_test_snippet.py
Created July 11, 2016 01:42 — forked from NotSqrt/settings_test_snippet.py
Another shot at this problem ..
class DisableMigrations(object):
def __contains__(self, item):
return True
def __getitem__(self, item):
return "notmigrations"
MIGRATION_MODULES = DisableMigrations()