Skip to content

Instantly share code, notes, and snippets.

View kenn's full-sized avatar

Kenn Ejima kenn

View GitHub Profile
@kenn
kenn / local-domain.md
Created August 18, 2023 07:23
Keep separate cookies and passwords for multiple projects

Local Domains for Development

tl;dr

Install dnsmasq to make all .test domains point to localhost on your Mac.

Why and how to set up .test domain on your Mac

When we work on a local machine for development, we usually point to localhost:3000 in the browser. But using that domain for everything comes with some downsides when you work on multiple projects.

import { useRevalidator } from '@remix-run/react'
import { useEffect } from 'react'
// Rendering will ensure all page loaders are revalidated according to a given
// frequency
export const Poller = ({ seconds }) => {
usePolling(seconds)
return null
}
def scroll_merge(klass, source_names, target_name, batch_size = 100):
Qdrant.recreate(target_name) # reset target collection
def generator(source_name):
offset = None
while True:
# Scroll https://qdrant.tech/documentation/points/#scroll-points
# https://github.com/qdrant/qdrant-client/blob/master/qdrant_client/qdrant_client.py#L412
result = Qdrant.client.scroll(
#!/usr/bin/env ruby
#------------------------------------------------------------------------------
# Aggregate Print useful information from /proc/[pid]/smaps
#
# pss - Roughly the amount of memory that is "really" being used by the pid
# swap - Amount of swap this process is currently using
#
# Reference:
# http://www.mjmwired.net/kernel/Documentation/filesystems/proc.txt#361
@kenn
kenn / gist:5228906
Last active February 15, 2016 07:16
DigitalOcean per-core pricing

CPU Price Performance: DigitalOcean vs Linode

On DigitalOcean, as you go up the plan, you get higher per-core price as well.

https://www.digitalocean.com/pricing

$5 1 core     - $5/core
$10 1 core - $10/core
@kenn
kenn / gist:7071032
Last active December 26, 2015 01:28
SELECT * FROM
(SELECT id FROM sort_keys ORDER BY sort_key) INNER JOIN main_table ON sort_keys.id = main_table.id
WHERE ... OFFSET 0 LIMIT 10
@kenn
kenn / gist:7061067
Last active December 25, 2015 23:59
Validating MinHash's errors
require 'digest'
a = (0..100000).map{|i| Digest::SHA1.hexdigest(i.to_s).hex }
a.map.with_index{|i,idx| i > a[idx-1] }.group_by{|i| i }.map{|k,v| [k,v.size] }
# => [[true, 499235], [false, 500766]]
# Undo require 'active_support/core_ext/object/to_json'
require 'yajl'
[Object, Array, Hash].each do |klass|
klass.class_eval <<-RUBY, __FILE__, __LINE__
def jsonize(options = nil)
::Yajl::Encoder.encode(self)
end
RUBY
end
E, [2013-04-22T15:04:52.652797 #8734] ERROR -- : listen loop error: closed stream (IOError)
E, [2013-04-22T15:04:52.652852 #8734] ERROR -- : /usr/local/rvm/gems/ruby-2.0.0-p0/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:652:in `select'
E, [2013-04-22T15:04:52.652886 #8734] ERROR -- : /usr/local/rvm/gems/ruby-2.0.0-p0/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:652:in `worker_loop'
E, [2013-04-22T15:04:52.652918 #8734] ERROR -- : /usr/local/rvm/gems/ruby-2.0.0-p0/gems/newrelic_rpm-3.6.0.83/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb:22:in `call'
E, [2013-04-22T15:04:52.652950 #8734] ERROR -- : /usr/local/rvm/gems/ruby-2.0.0-p0/gems/newrelic_rpm-3.6.0.83/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb:22:in `block (4 levels) in <top (required)>'
E, [2013-04-22T15:04:52.652981 #8734] ERROR -- : /usr/local/rvm/gems/ruby-2.0.0-p0/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:500:in `spawn_missing_workers'
E, [2013-04-22T15:04:52.653013 #8734] ERROR -- : /usr/local/rvm/gems/ruby
@kenn
kenn / gist:5191853
Last active December 15, 2015 03:08
# hdparm -tf /dev/xvda
/dev/xvda:
Timing buffered disk reads: 714 MB in 3.01 seconds = 237.55 MB/sec
# bonnie++ -b -u root
Version 1.96 ------Sequential Output------ --Sequential Input- --Random-
Concurrency 1 -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP /sec %CP