Skip to content

Instantly share code, notes, and snippets.

View NetguruGist's full-sized avatar

Netguru NetguruGist

View GitHub Profile
@NetguruGist
NetguruGist / serializers5.ruby
Created November 3, 2015 17:19
serializers5 ruby
[json response]
data: {
id: 1,
type: "users",
attributes: { name: "John" },
relationships: {
notes: [
{ id: 1, type: "notes" },
{ id: 2, type: "notes" }
]
@NetguruGist
NetguruGist / fibonacci4.ruby
Created October 31, 2015 14:50
fibonacci4 ruby
> gcd(nth_fibonacci(32), nth_fibonacci(33))
=> 1
@NetguruGist
NetguruGist / fibonacci2.ruby
Created October 31, 2015 14:50
fibonacci2 ruby
def gcd(x, y)
loop do
r = x % y
return y if r.zero?
x, y = y, r
end
end
@NetguruGist
NetguruGist / amazon1.ruby
Created October 31, 2015 14:51
amazon1 ruby
require 'benchmark'
require 'open-uri'
iterations = ARGV.first.to_i
S3_URL = 'http://s3.amazonaws.com/<supersecret>/images/1.original.jpg?1438008505'
CLOUDFRONT_URL = 'http://<supersecret>.cloudfront.net/images/1.original.jpg?1438008505'
Benchmark.bmbm(10) do |x|
x.report('cloudfront') { iterations.times{ open(CLOUDFRONT_URL) } }
x.report('s3') { iterations.times{ open(S3_URL) } }
@NetguruGist
NetguruGist / lazy1.ruby
Created December 1, 2015 08:18
lazy1 ruby
set-window-option -g mode-keys vi
bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-h) || tmux select-pane -L"
bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-j) || tmux select-pane -D"
bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-k) || tmux select-pane -U"
bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-l) || tmux select-pane -R"
bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys 'C-\\') || tmux select-pane -l"
@NetguruGist
NetguruGist / serializers1.ruby
Created October 30, 2015 08:28
serializers1 ruby
class User < ActiveRecord::Base
has_many :notes
end
class UserSerializer < ActiveModel::Serializer
attributes :id, :name
has_many :notes
end
```
```
@NetguruGist
NetguruGist / query3.ruby
Created November 3, 2015 13:23
query3 ruby
> ActiveRecord::Base.connection.execute("select count(*) from ( select distinct market_id from selections) as foo ").entries
(3717.6ms) select count(*) from ( select distinct market_id from selections) as foo
@NetguruGist
NetguruGist / augmented1.java
Created November 9, 2015 08:49
augmented1 java
public class CameraViewActivity extends Activity implements
SurfaceHolder.Callback,OnLocationChangedListener,OnAzimuthChangedListener{
private Camera mCamera;
private SurfaceHolder mSurfaceHolder;
private boolean isCameraviewOn = false;
private AugmentedPOI mPoi;
private double mAzimuthReal = 0;
private double mAzimuthTeoretical = 0;
tasks:
- name: remove admin account
user: name=admin state=absent remove=true
(...)
PLAY RECAP **************************************************************
<IP> : ok=3 changed=0 unreachable=0 failed=0