Skip to content

Instantly share code, notes, and snippets.

@artemave
artemave / gist:1521999
Created December 26, 2011 19:48
Slow down ssh on mac
1. edit /etc/services to change default ssh port to something exotic e.g. 24455 - we don't want to slow useful ssh connections
2. (re)start 'Remote login' in system prefs->sharing
3. sudo ipfw pipe 1 config bw 5KByte/s
4. sudo ipfw add 1 pipe 1 src-port 24455
Now `ssh localhost -p 24455` and experience the power of slow connection
Unslow it when you've had enough:
sudo ipfw delete 1
@artemave
artemave / gist:1718293
Created February 1, 2012 17:47
liquid_proxy prototype
require 'em-proxy'
require 'http/parser' # gem install http_parser.rb
require 'http_tools'
require 'awesome_print'
# > ruby em-proxy-http.rb
# > curl --proxy localhost:9889 www.google.com
host = "0.0.0.0"
port = 9889
@artemave
artemave / README.md
Last active October 1, 2015 05:08
ChildFork

ChildFork

Like ChildProcess but forks instead of creating new process. In certain cases (e.g, child code shares heavy initialization with parent; like ActiveRecord, etc.) should perform better than ChildProcess. On the flip side, it does not work on Windows and Jruby.

The main difference from plain Process.fork is that this one is guaranteed to not outlive parent process. Plus it implements some of ChildProcess api, so that those two can be hidden behind common interface.

Usage:

# Gemfile
@artemave
artemave / cut_the_crap.pl
Created April 20, 2012 09:09
Filter out the code you don't need to read in java source code, to get better idea on sloc
#!/usr/bin/env perl
use strict;
use warnings;
use File::Basename;
for my $fname (@ARGV) {
open(my $file, $fname) or die $!;
@artemave
artemave / gist:2493763
Created April 25, 2012 21:46
Coffee script factory pattern
class MyNamespace.MyView extends Backbone.View
@Factory: ->
create: ->
new MyView
# then pass it in router initialization
class MyRouter extends Backbone.Router
initialize: (opts = {}) ->
myview_factory = opts.myview_factory || new MyNamespace.MyView.Factory
@artemave
artemave / gist:3032649
Created July 2, 2012 10:46
change commit author
git filter-branch --commit-filter '
if [ "$GIT_COMMITTER_NAME" = "avetia01" ];
then
GIT_COMMITTER_NAME="artemave";
GIT_AUTHOR_NAME="artemave";
GIT_COMMITTER_EMAIL="artemave@gmail.com";
GIT_AUTHOR_EMAIL="artemave@gmail.com";
git commit-tree "$@";
else
git commit-tree "$@";
@artemave
artemave / gist:3077675
Created July 9, 2012 17:08
Turn text input into 'hotkey' input. jQuery plugin.
// Usage:
// $('#myinput').hotkeyInput();
(function($) {
$.fn.hotkeyInput = function() {
var self = this;
var specialKeys = {
20: "Capslock", 27: "Esc", 32: "Space", 33: "Pageup", 34: "Pagedown", 35: "End", 36: "Home",
37: "Left", 38: "Up", 39: "Right", 40: "Down", 45: "Insert", 46: "Del", 186: ";", 187: "=",
@artemave
artemave / gist:3543527
Created August 30, 2012 22:40
Let the Wise Rainbow Cow share bits of its wisdom
# put this in .zprofile, .profile, etc.
# you need `cowsay`, `lolcat` and `fortune` installed for The Cow to speak in its full color
# `lolcat` is a ruby gem - `gem install lolcat`
command -v fortune cowsay lolcat &> /dev/null && fortune | cowsay | lolcat
@artemave
artemave / gist:4030759
Created November 7, 2012 10:29
SlowDown.vim
function! SlowDown()
let l:rand = (localtime() % 100) + 100
execute 'sleep ' . l:rand . 'm'
endfunction
au CursorMoved,CursorMovedI * :call SlowDown()
@artemave
artemave / gist:4297714
Created December 15, 2012 18:03
vcr cassette shopify
---
http_interactions:
- request:
method: post
uri: https://legros-hammes-and-cummings1273.myshopify.com/admin/oauth/access_token
body:
encoding: US-ASCII
string: grant_type=authorization_code&code=74c98f3ae56aa2e1bc9c300279a5b159&client_id=44dd9799fbc268c36ef609f0c2386b8c&client_secret=a70f45c804421ec05c59f0673f6651d0&redirect_uri=http%3A%2F%2F127.0.0.1%3A17787%2Fauth%2Fshopify%2Fcallback
headers:
content-type: