Skip to content

Instantly share code, notes, and snippets.

View mariash's full-sized avatar

Maria Shaldybin mariash

  • Cloud Foundry
  • San Francisco, CA
View GitHub Profile
@mariash
mariash / exec.rb
Created October 4, 2012 00:24
ruby popen fds
open('/tmp/f','w'){|f| f << 'sekrit'}
f = open('/tmp/f')
exec("ruby -e 'p IO.open(#{f.fileno}).read'")
# Prints 'sekrit'
@mariash
mariash / copy_preserve.rb
Created October 5, 2012 00:24
FileUtils copy with preserve and symlink issue
# copy with preserve updates metadata of file and if file that symlink points to has not been copied yet it fails
require "fileutils"
`mkdir ./src`
`touch ./src/foo`
# Important that symlink name goes before source name in alphabetical order (bar points to foo)
`ln -s ./src/foo bar`
@mariash
mariash / npm-install-problem.sh
Created October 11, 2012 23:27
NPM saving current configuration in package.json and exit code 0 on failure
#!/bin/bash
# NPM_0_6_12=~/.nvm/v0.6.12/bin/npm NPM_0_6_8=~/.nvm/v0.6.8/bin/npm ./npm-install-problem.sh
# Install module with npm from node v0.6.12 and then use npm from node v0.6.8 to rebuild it and see it fail
# + exit code is 0 with the force option even on failure
# Npm saves install information in package.json so next time npm build is run on package with different configuration it may fail
$NPM_0_6_12 install bcrypt@0.7.2
cd ./node_modules/bcrypt
# package.json was updated with scripts -> install that looks like "node-gyp rebuild"
@mariash
mariash / cc_rblineprof.log
Created January 31, 2014 18:21
rblineprof output when hitting /v2/apps?inline-relations-depth=1
[Rack::Lineprof] ===============================================================
vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.7.1.180/lib/new_relic/agent/transaction.rb
 | 32 # Return the currently active transaction, or nil.
 | 33 def self.current
 333.3ms 32234 | 34 self.stack.last
 | 35 end
 | 36
 .......
 | 53
@mariash
mariash / MYAppDelegate.m
Last active August 29, 2015 14:02
Importing documents in iOS application
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if (url != nil && [url isFileURL]) {
NSError *error;
[[MYFileManager sharedInstance] importAttachment:url.path error:&error];
if (error != nil) {
[[MYAlertDisplayer sharedInstance]
displayAlert:@"Error" withMessage:@"Failed to import file"];
@mariash
mariash / gist:2a5d6203be5ff22ec971
Last active August 29, 2015 14:02
Debugging stuck ruby process with GDB
(gdb) call (void) close(1)
(gdb) call (void) close(2)
(gdb) shell tty
/dev/pts/1
(gdb) call (int) open("/dev/pts/1", 2, 0)
(gdb) call (int) open("/dev/pts/1", 2, 0)
(gdb) call (void)rb_backtrace()
@mariash
mariash / result
Last active August 29, 2015 14:04
HTTPClient tests
2 tests, 2 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
7.91 tests/s, 7.91 assertions/s
mariash@mariash-mac:~/workspace/test_httpclient $ ruby main.rb -v
Loaded suite main
Started
TestHTTPClient:
test_get_chunked_file: [2014-07-29 22:11:37] INFO WEBrick 1.3.1
[2014-07-29 22:11:37] INFO ruby 2.1.2 (2014-05-08) [x86_64-darwin13.0]
@mariash
mariash / gist:9f14d8e87f180acc0b3b
Last active August 29, 2015 14:06
Rspec skip in before(:all) exits with 1

→ cat test_spec.rb

describe "hello" do
  before do
    skip "skipped"
  end
  it "works" do
  end
end
@mariash
mariash / gist:d1964168411a67e9d867
Created November 4, 2014 05:12
Setting up port forwarding
https://github.com/cloudfoundry/bosh-lite/blob/master/templates/vagrant-aws.tpl#L63
@mariash
mariash / main.go
Created June 23, 2015 14:17
Packages sharing the same dependency
package main
import (
"github.com/cloudfoundry/bosh-utils/retrystrategy"
"github.com/pivotal-golang/clock"
)
func main() {
clock.Clock
retrystrategy.Clock