Skip to content

Instantly share code, notes, and snippets.

View aarti's full-sized avatar
🎯
Focusing

aarti

🎯
Focusing
  • San Francisco Bay Area
View GitHub Profile
@katylava
katylava / git-selective-merge.md
Last active February 27, 2024 10:18
git selective merge

Update 2022: git checkout -p <other-branch> is basically a shortcut for all this.

FYI This was written in 2010, though I guess people still find it useful at least as of 2021. I haven't had to do it ever again, so if it goes out of date I probably won't know.

Example: You have a branch refactor that is quite different from master. You can't merge all of the commits, or even every hunk in any single commit or master will break, but you have made a lot of improvements there that you would like to bring over to master.

Note: This will not preserve the original change authors. Only use if necessary, or if you don't mind losing that information, or if you are only merging your own work.

@yuya-takeyama
yuya-takeyama / binarytree.rb
Created February 5, 2011 14:32
Binary Tree implemented in Ruby.
module BinaryTree
class Node
attr_reader :word, :count, :left, :right
include Enumerable
def initialize(word)
@word, @count = word, 1
end
@exoer
exoer / db_server.rb
Created July 4, 2011 17:58 — forked from coderanger/db_server.rb
Create postgres users and databases from Chef
include_recipe "postgresql::server90"
# inspiration from
# https://gist.github.com/637579
execute "create-root-user" do
code = <<-EOH
psql -U postgres -c "select * from pg_user where usename='root'" | grep -c root
EOH
command "createuser -U postgres -s root"
@3dd13
3dd13 / ruby_ftp_example.rb
Created November 5, 2011 17:08
Sample code of using Ruby Net::FTP library. Login to FTP server, list out files, check directory existence, upload files
require 'net/ftp'
CONTENT_SERVER_DOMAIN_NAME = "one-of-the-ftp-server.thought-sauce.com.hk"
CONTENT_SERVER_FTP_LOGIN = "saucy-ftp-server-login"
CONTENT_SERVER_FTP_PASSWORD = "saucy-ftp-server-password"
# LOGIN and LIST available files at default home directory
Net::FTP.open(CONTENT_SERVER_DOMAIN_NAME, CONTENT_SERVER_FTP_LOGIN, CONTENT_SERVER_FTP_PASSWORD) do |ftp|
files = ftp.list
@brentertz
brentertz / rvm2rbenv.txt
Created November 21, 2011 23:00
Switch from RVM to RBENV
## Prepare ###################################################################
# Remove RVM
rvm implode
# Ensure your homebrew is working properly and up to date
brew doctor
brew update
## Install ###################################################################
@slok
slok / jboss_apache.md
Created December 31, 2011 09:06
Setup for jboss 7 with apache and mod_cluster in ubuntu 11.10

Preparing Jboss environment

Create Jboss user and group

Create a group for a system user (daemnos and program users like www-data, mysql...)

# addgroup --system jboss

Create a user (system user, without home -> See below the command, to the jboss group and no login shell)

15:39:06,062 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "current-knob.yml"
15:39:06,639 INFO [org.torquebox.core.runtime] (Thread-109) Initialize? true
15:39:06,639 INFO [org.torquebox.core.runtime] (Thread-109) Initializer=org.torquebox.web.rack.RackRuntimeInitializer@7df86f75
15:39:06,979 INFO [org.torquebox.core.runtime] (Thread-109) Setting up Bundler
15:39:08,138 INFO [stdout] (Thread-109) Could not find rake-0.8.7 in any of the sources
15:39:08,138 INFO [stdout] (Thread-109) Run `bundle install` to install missing gems.
15:39:08,139 ERROR [org.torquebox.core.runtime] (Thread-109) Error during evaluation: require %q(bundler/setup): org.jruby.exceptions.RaiseException: (SystemExit) exit
at org.jruby.RubyKernel.exit(org/jruby/RubyKernel.java:856) [jruby.jar:]
at org.jruby.RubyKernel.exit(org/jruby/RubyKernel.java:825) [jruby.jar:]
at (Anonymous).(root)(/opt/torquebox-current/jruby/lib/ruby/gems/1.8/gems/bundler-1.0.22/lib/bundler/setup.rb:14) at org.jruby.RubyK
@nathanaschbacher
nathanaschbacher / sudo_env_output
Created March 13, 2012 20:10
Torquebox 2.x errors trying to daemonize the gem install (sudo jruby -S rake torquebox:upstart:start)
GEM_HOME=/usr/local/rvm/gems/jruby-1.6.7
TERM=xterm-256color
JBOSS_HOME=/usr/local/rvm/gems/jruby-1.6.7@global/gems/torquebox-server-2.0.0.cr1-java/jboss
PATH=/usr/local/rvm/gems/jruby-1.6.7/bin:/usr/local/rvm/gems/jruby-1.6.7@global/bin:/usr/local/rvm/rubies/jruby-1.6.7/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
JRUBY_HOME=/usr/local/rvm/rubies/jruby-1.6.7
LANG=en_US.UTF-8
TORQUEBOX_HOME=/usr/local/rvm/gems/jruby-1.6.7@global/gems/torquebox-server-2.0.0.cr1-java
GEM_PATH=/usr/local/rvm/gems/jruby-1.6.7:/usr/local/rvm/gems/jruby-1.6.7@global
JRUBY_OPTS=--1.9
SHELL=/bin/bash
@rklemme
rklemme / BitSet.rb
Last active October 5, 2015 07:58
Basis for a bit set which uses String as storage. Storage is split up into multiple String instances to avoid too large allocations.
#!/usr/bin/ruby
# Implementation of a bit set which stores membershio in binary
# Strings managed in chunks.
class BitSet
ZERO = "\000".encode(Encoding::BINARY).freeze
DEFAULT_SEGMENT_SIZE = 1024 * 1024
# Create the BitSet instance. If max_num is given, we preallocate
# as much memory as needed.
@jboner
jboner / latency.txt
Last active May 29, 2024 05:28
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD