Skip to content

Instantly share code, notes, and snippets.

@litch
litch / digtest.sh
Created April 18, 2024 20:07
Digtest for diagnosing DNS timings
#!/bin/bash
# depends on gawk
# if running in a netshoot container, you need to install it:
# apk add --no-cache gawk
# Filename to store the results
output_file="dig_results.txt"
times_file="query_times.txt"
# Clear files if they already exist
I inlined the code from microAjax there, to keep dependencies at 0. I think the following cite satisfies the license?
https://code.google.com/archive/p/microajax/
This code was referenced extensively:
https://bitbucket.org/snippets/jdubray/9dgKp/sam-sample
@litch
litch / shopify.md
Last active March 20, 2019 07:50 — forked from lambtron/shopify.md
segment event tracking for shopify
title sidebar
Segment Event Tracking for Shopify
Shopify

Segment makes it simple for Shopify merchants to integrate analytics, email marketing, advertising and optimization tools. Rather than installing all your tools individually, you just install Segment once. We collect your data, translate it, and route it to any tool you want to use with the flick of a switch. Using Segment as the single platform to manage and install your third-party services will save you time and money.

The guide below explains how to install Segment in your Shopify store. All you need to get up and running is copy and paste a few snippets of code into your theme editor. (You don't have to edit the code or be versed in JavaScript.) The following guide will show you how, step by step.


0xa8BA5E97DB500655c18A8aa3FEd6DA5d6c8e868F

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@litch
litch / health.rb
Created July 1, 2016 19:48
Health check HTTP endpoint for a ruby (micro)service
# This is used to provide a Health Check HTTP endpoint
# 1- Each project should have a particular endpoint(s), they should not overlap
# so that mulitple services running on a single node will not confuse our
# operations (this isn't docker, there are rules.)
# 2- If you pass a block to the build method, that code will be evaluated and
# merged into the check. The return type of that block should be a hash
# Usage examples:
=render @memory_page.approved_comments
= simple_form_for [@memory_page, Comment.new], html: {class: 'form-inline'} do |f|
.form-inputs
.row
.col-md-12
= f.input :comment, label: "Add Your Comment", input_html: {class: 'editable'}
.row#hidden_form_elements.hide //I have some JS callback that will display these fields once the parent input has been edited
.col-md-6
= f.input :name
.col-md-6
@litch
litch / postgres_experiment.mdown
Created December 11, 2013 17:32
Performance testing looking in arrays of uuids vs arrays of integers

I've added some functionality recently to be able to search a business by old UUID's, and am going to check the performance of it. So this little snippet will create a million rows in each of two tables and I'll post the results here as I get them (currently it's creating the rows, very slowly, probably because of the 4x uuid generation then indexing on the uuid column and the merged_uuids columns (and the indexes).

CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public;
COMMENT ON EXTENSION "uuid-ossp" IS 'generate universally unique identifiers (UUIDs)';


CREATE TABLE test_record_uuid (
    id uuid DEFAULT uuid_generate_v4() NOT NULL,
    name character varying(255),
@litch
litch / irb.rb
Last active December 29, 2015 10:59
Ruby/Rails Time vs Datetime
☺ ~% irb
>> Time.now.to_s
=> "2013-11-26 09:33:52 -0600"
>> "2013-11-26 09:33:52 -0600".to_datetime
NoMethodError: undefined method `to_datetime' for "2013-11-26 09:33:52 -0600":String
from (irb):2
from /Users/litch/.rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'
>> "2013-11-26 09:33:52 -0600".to_time
NoMethodError: undefined method `to_time' for "2013-11-26 09:33:52 -0600":String
from (irb):3
@litch
litch / module_class_instance_method_comparison.rb
Created November 3, 2013 03:43
Slightly surprisingly small amount of performance difference for these three methods of getting things done...
require 'redis'
require 'benchmark'
module ModuleMethods
def self.record_metric(name)
$REDIS.lpush(translate_name(name), Time.now.to_f)
end
def self.translate_name(queue)