Skip to content

Instantly share code, notes, and snippets.

View ArthurN's full-sized avatar

Arthur Nisnevich ArthurN

View GitHub Profile
@ArthurN
ArthurN / assign_sids.js
Created December 15, 2011 04:57
MongoDB error doing update shell/collection.js:200 (9001 socket exception?)
var startTime = (new Date()).getTime();
var total = db.items.count({_sid: { $exists: false } });
diff = ((new Date()).getTime() - startTime) / 1000.0;
print(diff + "s to count items without _sid");
print(total + " items need to be updated");
var done = 0;
db.items.find({_sid: { $exists: false } }).forEach(function (item) {
if (item.topic_ids != null && item.topic_ids.length > 0) {
item._sid = item.topic_ids[0];
@ArthurN
ArthurN / provider.js
Created October 21, 2011 20:47
Parsing Domain Names ("providers")
// from:
// http://www.webtalkforums.com/showthread.php/37600-Simple-JavaScript-RegEx-to-Parse-Domain-Name
var parts = /^((\w+):\/\/)?((\w+):?(\w+)?@)?([^\/\?:]+):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(\w*)/.exec(item['url'])
if (parts != null) {
providerUrl = parts[1] + parts[6];
providerName = parts[6].replace("www.", "");
} else {
// Graceful fail
//console.debug("Failed URL parsing on: " + item['url']);
@ArthurN
ArthurN / gist:1246057
Created September 27, 2011 19:56
Print date/time and query length (ms) from mongod log file
awk -F' ' '{ print $1 " " $2 " "$3 " " $4 " " $(NF) }' mongod.log | grep 'ms'
@ArthurN
ArthurN / gist:1090842
Created July 18, 2011 22:24
isotope fix for nil exception
source = included_scripts_source || ""
source += " " + IO.read(isotope_file_path)
context = ExecJS.compile(source)
script = "Isotope(#{view_file_content.to_json}, #{options[:locals].to_json})"
output = context.eval(script)
@ArthurN
ArthurN / gist:1088493
Created July 18, 2011 03:29
therubyracer 0.9.2 segfault on Ruby 1.9.2
=> Booting WEBrick
=> Rails 3.0.7 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
ActionView::Base included ViewHelpers
ActionController::Base included ViewHelpers
[2011-07-17 21:27:09] INFO WEBrick 1.3.1
[2011-07-17 21:27:09] INFO ruby 1.9.2 (2011-02-18) [x86_64-darwin10.7.0]
[2011-07-17 21:27:09] INFO WEBrick::HTTPServer#start: pid=13393 port=3000
/Users/arthur/.rvm/gems/ruby-1.9.2-p180/gems/therubyracer-0.9.2/lib/v8/context.rb:17: [BUG] Segmentation fault
@ArthurN
ArthurN / generate_password_hash.sh
Created June 22, 2011 02:44
Useful CentOS Commands
echo "password"|openssl passwd -1 -stdin
@ArthurN
ArthurN / kill-sidekiq.sh
Created August 24, 2015 18:51
Kill Duplicate Sidekiq processes
#!/bin/bash
if [ $(pgrep -f sidekiq | wc -l) -gt 1 ]; then
kill $(pgrep -f sidekiq | grep -v $(pgrep -of sidekiq) | sort -n | uniq | awk '{printf $1" "}');
fi
@ArthurN
ArthurN / gist:e980d723a6d63e9fc766
Created November 22, 2014 01:21
pdf-reader-get-fields.rb
def get_fields
# We have to use #send because AFAIK, PDF::Reader does not expose the root object anywhere
acroform = @reader.send(:root)[:AcroForm]
# PDF::Reader encapsulates each piece of PDF data in #objects. The field_refs are really references to
# these objects. We iterate through and de-reference the actual object, creating a AcroField based on its
# data
field_refs = @reader.objects[acroform][:Fields] unless acroform.nil?
fields = field_refs.map do |field_ref|
AcroField.new(@reader.objects[field_ref])
@ArthurN
ArthurN / gist:f16ad0e6958a0af73d39
Created November 10, 2014 21:08
AWS permissions
# From http://breakthebit.org/post/77505127462/up-your-security-on-amazon-aws
{
"Statement": [
{
"Sid": "AllowPublicRead",
"Action": [
"s3:ListBucket",
"s3:GetObject",
"s3:PutObject",
"s3:PutObjectAcl",
@ArthurN
ArthurN / gist:e13637dce27d15168d4b
Last active August 29, 2015 14:07
pcos-test.sh
# Extract PDF field names and positions using pCOS:
./pcos --extended field "FT fullname Rect[0] Rect[1] Rect[2] Rect[3]" fw9.pdf
# CSV format, also output pagesize as the first line:
./pcos --extended pagesize "width height" --extended field "FT fullname V Rect[0] Rect[1] Rect[2] Rect[3]" --format "(VAL,)\n" --replace missing "" test.pdf