Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# The easiest way to figure this out is to create a re-remapping in System Preferences ui, and then
# `defaults -currentHost read | grep com.apple.keyboard.modifiermapping`
keyboard_id="1452-632-0"
config_key="com.apple.keyboard.modifiermapping.${keyboard_id}"
# key_left_cmd=30064771299
key_right_cmd=30064771303
key_esc=30064771113
@krasnoukhov
krasnoukhov / 2013-01-07-profiling-memory-leaky-sidekiq-applications-with-ruby-2.1.md
Last active October 4, 2023 21:53
Profiling memory leaky Sidekiq applications with Ruby 2.1

My largest Sidekiq application had a memory leak and I was able to find and fix it in just few hours spent on analyzing Ruby's heap. In this post I'll show my profiling setup.

As you might know Ruby 2.1 introduced a few great changes to ObjectSpace, so now it's much easier to find a line of code that is allocating too many objects. Here is great post explaining how it's working.

I was too lazy to set up some seeding and run it locally, so I checked that test suite passes when profiling is enabled and pushed debugging to production. Production environment also suited me better since my jobs data can't be fully random generated.

So, in order to profile your worker, add this to your Sidekiq configuration:

if ENV["PROFILE"]
@rastasheep
rastasheep / keyrepeat.shell
Last active January 1, 2020 20:09 — forked from kconragan/keyrepeat.shell
Enable key repeat in Apple Lion for Atom in Vim mode
# Mac OS X Lion introduced a new, iOS-like context menu when you press and hold a key
# that enables you to choose a character from a menu of options. If you are on Lion
# try it by pressing and holding down 'e' in any app that uses the default NSTextField
# for input.
#
# It's a nice feature and continues the blending of Mac OS X and iOS features. However,
# it's a nightmare to deal with in Atom if you're running vim mode,
# as it means you cannot press and hold h/j/k/l to move through your file. You have
# to repeatedly press the keys to navigate.
@eneagoe
eneagoe / gist:7890670
Created December 10, 2013 13:36
benchmark number reverse
require 'benchmark'
n, exec_time = 123456789123456789123456789123456789123456789, 0
100000.times do
exec_time += Benchmark.measure do
r = 0
r, n = (r*10 + n % 10), n / 10 while n != 0
r
end.real
@paulmach
paulmach / serve.go
Last active November 13, 2024 16:17
Simple Static File Server in Go
/*
Serve is a very simple static file server in go
Usage:
-p="8100": port to serve on
-d=".": the directory of static files to host
Navigating to http://localhost:8100 will display the index.html or directory
listing file.
*/
package main
/*jslint continue:true*/
/**
* Adapted from {@link http://www.bulgaria-web-developers.com/projects/javascript/serialize/}
* Changes:
* Ensures proper URL encoding of name as well as value
* Preserves element order
* XHTML and JSLint-friendly
* Disallows disabled form elements and reset buttons as per HTML4 [successful controls]{@link http://www.w3.org/TR/html401/interact/forms.html#h-17.13.2}
* (as used in jQuery). Note: This does not serialize <object>
* elements (even those without a declare attribute) or
@scy
scy / opening-and-closing-an-ssh-tunnel-in-a-shell-script-the-smart-way.md
Last active October 27, 2024 19:13
Opening and closing an SSH tunnel in a shell script the smart way

Opening and closing an SSH tunnel in a shell script the smart way

I recently had the following problem:

  • From an unattended shell script (called by Jenkins), run a command-line tool that accesses the MySQL database on another host.
  • That tool doesn't know that the database is on another host, plus the MySQL port on that host is firewalled and not accessible from other machines.

We didn't want to open the MySQL port to the network, but it's possible to SSH from the Jenkins machine to the MySQL machine. So, basically you would do something like

ssh -L 3306:localhost:3306 remotehost

@estum
estum / user.rb
Last active December 21, 2015 05:49
Migrate passwords from legacy systems to Devise
# updated variant of older solution:
# http://www.davidverhasselt.com/2012/05/13/how-to-migrate-passwords-from-legacy-systems-to-devise
class User < ActiveRecord::Base
# ...
def valid_password?(password)
if legacy_password?
# Use Devise's secure_compare to avoid timing attacks
@rusilko
rusilko / dev_start.sh
Last active April 15, 2017 04:48
Simple bash script to quickly fire up your Rails working environment.
#!/bin/bash
# Function displaying wrong usage information
# Proper usage is: ./dev_start.sh Rails-Project-Folder
usage()
{
cat << EOF
usage: $0 Rails-Project-Folder
EOF
}
<form method="post" action="https://gateway.pagosonline.net/apps/gateway/index.html" id="pagosonline_form" name="pagosonline_form">
<input type="hidden" name="descripcion" value="{$p.gtitle|stripslashes}" />
<input type="hidden" name="valor" value="{$value[1]}" id='povalue'/>
<input type="hidden" name="usuarioId" value="{$login}" />
<input type="hidden" name="moneda" value="COP" />
<input name="lng" type="hidden" value="es">
<input name="iva" type="hidden" value="0.00">
<input name="baseDevolucionIva" type="hidden" value="0.00">
<input type="hidden" name="emailComprador" value="{$emailcomprador}" />
<input type="hidden" name="url_respuesta" value="{$baseurl}/thank_you?g={$eid}" /> <!--Url where user is returned-->