Skip to content

Instantly share code, notes, and snippets.

@eegrok
eegrok / gist:79d29a705e0c600460f0c4a1c2170835
Last active Sep 13, 2020
one liners for tcp socket connection test in ruby
View gist:79d29a705e0c600460f0c4a1c2170835
# client
ip_addr = 'server_addr'; require 'socket'; loop { begin; sock = TCPSocket.new(ip_addr, 2000); while (str = sock.readline) do puts str; end; rescue EOFError; sleep 1; next; rescue Errno::ECONNREFUSED; puts "FAIL"; end; sleep 1; }
# server
require 'socket'; server = TCPServer.new 2000; loop { Thread.start(server.accept) do |client| client.puts "Hello !"; client.puts "Time is #{Time.now}"; client.close; puts "Handled request at #{Time.now}"; end; }
@eegrok
eegrok / mysql-import-individual-table
Created Nov 22, 2014
extract individual tables from database dump, for import -- mysql
View mysql-import-individual-table
touch /tmp/empty
ack "Table structure" /path/to/database_backup.sql /tmp/empty
it spits out something like this:
...
56160:-- Table structure for table `sub_human`
56195:-- Table structure for table `fool`
56385:-- Table structure for table `fool_games`
56465:-- Table structure for table `fool_games_old`
56657:-- Table structure for table `fool_games_texts`
@eegrok
eegrok / cltools.sh
Last active Aug 29, 2015 — forked from jellybeansoup/cltools.sh
install command line tools on osx / other libraries as well
View cltools.sh
#!/bin/sh
##
# Install autoconf, automake, libtool and pkg-config smoothly on Mac OS X.
# Newer versions of these libraries may be available and may work better on OS X
#
# This script is originally from http://jsdelfino.blogspot.com.au/2012/08/autoconf-and-automake-on-mac-os-x.html
#
export build=~/src # or wherever you'd like to build
@eegrok
eegrok / curl-ca-cert-import.txt
Created Apr 16, 2014
curl SSL3_GET_SERVER_CERTIFICATE error fix
View curl-ca-cert-import.txt
# I recently got the following error while using curl:
# curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
# error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
openssl s_client -connect www.whateverserver.com:443 |tee logfile
# then QUIT <RETURN>
# copy from BEGIN CERTIFICATE to END CERTIFICATE into /tmp/certstuff.pem
openssl x509 -inform PEM -in /tmp/certstuff.pem -text -out certdata
cat certdata
# in there, I saw this line:
@eegrok
eegrok / locate.updatedb.comment
Created Apr 8, 2014
locate.updatedb on osx as root instead of nobody user -- indexes home directory files
View locate.updatedb.comment
# comment out this region to index as root according to:
# http://apple.stackexchange.com/questions/84532/how-can-i-search-my-entire-drive-for-a-file-without-getting-recursively-stuck-in/84556#84556
# if [ "$(id -u)" = "0" ]; then
# rc=0
# export FCODES=`mktemp -t updatedb`
# chown nobody $FCODES
# tmpdb=`su -fm nobody -c "$0"` || rc=1
# if [ $rc = 0 ]; then
# install -m 0444 -o nobody -g wheel $FCODES /var/db/locate.database
# fi
View ubuntu-install.txt
#instructions for ubuntu 12.04
sudo apt-get -y update
sudo apt-get install git emacs curl build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev libmysql-ruby libmysqlclient-dev
cd /tmp
#install ruby -- from: http://stackoverflow.com/questions/16222738/how-to-install-ruby-2-0-0-correctly-on-ubuntu-12-04
wget http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz
tar -xvzf ruby-2.0.0-p353.tar.gz
cd ruby-2.0.0-p353/
./configure --prefix=/usr/local
View gist:8851553

general settings

  • turn off key clicks: Progrm + backslash

remap - any platform (press they key you want it to be first, then the key you will press to get that)

  • Tab --> Caps Lock
  • Esc --> Tab
  • Back Space --> Ctrl (left)
  • Delete --> Alt (left)
  • Down Arrow --> ]}
  • [{ --> Down Arrow
@eegrok
eegrok / git-patch-example.sh
Created Feb 28, 2013
save patch / apply it using git
View git-patch-example.sh
#this will save off a single commits patch, so you can apply it
# if you leave off from --stdout to the right, it'll create a patchfile in the current directory with a name
# that includes the comment from the commit
git format-patch -1 095e61f --stdout > /tmp/patchname.patch
# this will check the patch to see if any conflicts will arise when applying it
git apply --check /tmp/patchname.patch
# this will apply the patch
git apply /tmp/patchname.patch
@eegrok
eegrok / toggle-mic-mute.applescript
Last active Dec 13, 2015
applescript to toggle mute / notify via growl
View toggle-mic-mute.applescript
tell application "System Events"
set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell
if isRunning then
tell application id "com.Growl.GrowlHelperApp"
-- Make a list of all the notification types
-- that this script will ever send:
set the allNotificationsList to ¬
{"Microphone Muted", "Mic Live"}
@eegrok
eegrok / README.md
Created Sep 13, 2012
CC Validation
View README.md

Example Usage -- use ruby 1.9.3

git clone git@gist.github.com:3713188.git ccvalidator

cd ccvalidator

cat input1.dat | ./validate_cards.rb

ruby test/credit_card_validator_spec.rb