Skip to content

Instantly share code, notes, and snippets.

@yannvery
yannvery / GitReminder.md
Last active August 29, 2015 14:03
Git reminder

GitReminder

Just a reminder about git commands, enjoy!

Undo 'git add' before commit
git reset
Mark file as removed
@yannvery
yannvery / get_follower.rb
Created July 8, 2014 13:52
Get twitter followers with twitter gem and deal with rate limit
# Source : https://github.com/sferik/twitter/issues/517
def tw_follower_ids
$client.follower_ids.to_a
rescue Twitter::Error::TooManyRequests => error
p error
p 'tw_follower_ids sleep ' + error.rate_limit.reset_in.to_s
sleep error.rate_limit.reset_in
retry
end
@yannvery
yannvery / fetch_all_friends.rb
Created July 8, 2014 13:55
Fetch all twitter friends of a user
require 'csv'
require 'twitter'
def twitter_client
@twitter_client ||= Twitter::REST::Client.new do |config|
config.consumer_key = 'XXXXXX'
config.consumer_secret = 'XXXXXX'
config.access_token = 'XXXXXX'
config.access_token_secret = 'XXXXXX'
end
@yannvery
yannvery / gem_list_reminder.md
Created July 10, 2014 15:01
Gem List Reminder for Dev and Testing

Gem list reminder

Development

###pry-rails' Source : https://github.com/rweng/pry-rails

Description : Use pry instead of irb when you call rails console. Pry is a powerful alternative to the standard IRB shell for Ruby. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing.

###pry-doc' Source : https://github.com/pry/pry-doc

@yannvery
yannvery / abbrev_number.rb
Last active August 29, 2015 14:05
Rails helper to abbrev number
def abbrev_number(number,decimal)
l=number.to_s.length - 1
"%.#{decimal}f%s"%[number.to_f/10**(l-l%3)," kMGTPE"[l/3]]
end
require "rubygems"
begin
require 'sequel'
rescue LoadError
puts "Please run gem install sequel"
exit!
end
DB = Sequel.connect(:adapter => 'mysql2',
:host => '127.0.0.1',
@yannvery
yannvery / enable_disable_ftp.md
Last active August 29, 2015 14:05
Enable or Disable ftp server on OSX maverick

Enable FTP server on OSX maverick

sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist

Disable FTP serveur

sudo -s launchctl unload -w /System/Library/LaunchDaemons/ftp.plist

@yannvery
yannvery / OSX_tips.md
Last active August 29, 2015 14:05
Some tips about OSX

OSX Tips

If you don't want you wifi stopped when you lock OSX

I assume here that wifi card is on en0 /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport en0 prefs DisconnectOnLogout=NO

How to lock screen on OSX ( macbook air )

ctrl + shift(right) + power

@yannvery
yannvery / date_time_to_with_timezone.rb
Created September 4, 2014 15:26
Pure Ruby DateTime conversion to local timezone
#Simply to do this with rails but how to with ruby only
#Parse
dt = DateTime.parse(issue.updated_at.to_s)
# Convert
local_dt = dt.new_offset(DateTime.now.offset)
# Display
local_dt.strftime("%I:%M %p - %d-%b-%Y")
@yannvery
yannvery / ping.rb
Created September 15, 2014 14:53
Resolve dns address with ruby
require 'socket' #=> true
IPSocket::getaddress("www.google.com") #=> "74.125.79.147"