Skip to content

Instantly share code, notes, and snippets.

@en30
en30 / make_a_post_on_bluesky.livemd
Created May 6, 2023 07:09
A Livebook notebook to make a post on Bluesky.

Make a post on Bluesky

Mix.install([
  {:req, "~> 0.3"},
  {:jason, "~> 1.4.0"},
  {:kino, "~> 0.9.1"}
])
@en30
en30 / application.rb
Last active December 16, 2020 15:04
Chotto Matte
require_relative "boot"
require "rails/all"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module YourApp
class Application < Rails::Application
function peco-docker-compose () {
local selected_dir=$(ghq list --full-path | while read repo; do [ -f "${repo}/docker-compose.yml" ] && echo "$repo"; done | peco --query "$LBUFFER")
if [ -n "$selected_dir" ]; then
docker-compose --file "${selected_dir}/docker-compose.yml" --project-name "$(basename $selected_dir)" $*
fi
}
@en30
en30 / charset.ts
Created September 27, 2018 05:51
handle charset
import { AxiosResponse } from 'axios';
import contentType = require('content-type');
import cheerio = require('cheerio');
type Charset = string;
type IntermediateResult = Charset | null;
// to assert elements as tuple (inferred Array<string | Buffer>)
const bomify = ([c, bytes]) => ([c, Buffer.from(bytes)] as [Charset, Buffer]);
const BOMS: ReadonlyMap<Charset, Buffer> = new Map([
function peco-agsed() {
ag $1 | sed "s/$1/$1 => $2/g" | peco | awk -F: '{print $2; print $1}' | parallel -N 2 sed -i "''" '"'{1} s/$1/$2/g'"' {2}
}
SEG_NUMS = %w{3f 06 5b 4f 66 6d 7d 27 7f 6f}.map(&:hex)
def candidates(changable_bits, on_bits)
# onとchangable_bitsでnをカバーできる && onがはみ出していない
SEG_NUMS.select { |n|
((on_bits | changable_bits) & n == n) && ((on_bits &~ n) == 0)
}.map {|i| SEG_NUMS.index(i) }
end
# 怪しい
_ = require 'lodash'
module.exports = ({target, topBarrier, upperBound, bottomBarrier, lowerBound, wait, stickIf})->
getLowerBound = (topBarrier)->
return 0 unless topBarrier
topBarrier = topBarrier?() || topBarrier
topBarrierRect = topBarrier.getBoundingClientRect()
window.scrollY + topBarrierRect.bottom
getUpperBound = (bottomBarrier)->
return document.documentElement.getBoundingClientRect().height unless bottomBarrier
@en30
en30 / pg_gmetric.sh
Created November 3, 2014 11:35
A script to collect PostgreSQL's metrics by ganglia
#!/bin/bash
DBNAME="$1"
export PGPASSWORD="$2"
CACHE_FILE="/tmp/pg_gmetric"
OLD_CACHE_FILE="$CACHE_FILE.old"
pg_query() {
_NAME="$1"
_COMMAND="$2"
@en30
en30 / fizzbuzz.js
Last active August 29, 2015 14:08
// https://gist.github.com/kazuho/3300555
// の参照先の切り替えを隠蔽しようと思ったら
// ただの愚直な実装になった
var generator = function(n, name){
var current = {f: function(){ return name; }},
doNothing = function(){},
o = current;
while(--n) {
# depends on peco, chrome-cli
function peco-chrome-tabs () {
local tab_id=$(chrome-cli list tabs | peco | sed -e s/.*:// -e s/].*//)
if [ -n "$tab_id" ]; then
chrome-cli activate -t $tab_id
fi
}