Skip to content

Instantly share code, notes, and snippets.

View AlwinaO's full-sized avatar

Alwina Oyewoleturner AlwinaO

View GitHub Profile
function makeRequest(url) {
httpRequest = new XMLHttpRequest();
if (!httpRequest) {
displayErrorMsg('Sorry, there was a problem making the request!');
return false;
}
httpRequest.onreadystatechange = receiveRequest;
httpRequest.open('GET', url);
httpRequest.send();
}
@nnja
nnja / taking_notes.py
Last active June 28, 2019 16:49
Python script to select a random person to take notes in a meeting ⌨️🎉
import random
participants = ["Lena", "Seth", "Paul", "Suz", "Nina", "Burke", "Todd"]
print(f"{random.choice(participants)} is taking notes.")
@clarkdave
clarkdave / pg_interval.rb
Last active July 9, 2019 00:57
Support for PostgreSQL `interval` type in Rails 4. Although ActiveRecord supports `interval` by default, it turns it into a string (and tells Postgres the column is type string, too). This means you don't get any proper interval goodness. By sticking this code into an initialiser, ActiveRecord will create proper `interval` column types in Postgr…
#
# This will force ActiveRecord to create proper `interval` column types in PostgreSQL
#
# def change
# add_column :leases, :period, :interval
# end
#
# This applies to a generated `schema.rb` file too.
#
# No special OID type is applied to an `interval` type. Rails will treat it as a string, although
@christianesperar
christianesperar / Ruby Factorial Method
Created March 2, 2014 14:41
Ruby Factorial Method
class Integer
def factorial
result = 0
self.downto(1) { |number| result == 0 ? result = number : result *= number }
return result
end
end
@vollnhals
vollnhals / pg_interval_rails_5_1.rb
Last active July 13, 2020 13:44
Implementation of interval database type in Rails 5.1
# implementation from https://github.com/rails/rails/pull/16919
# activerecord/lib/active_record/connection_adapters/postgresql/oid/interval.rb
require "active_support/duration"
module ActiveRecord
module ConnectionAdapters
module PostgreSQL
watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf $TMPDIR/npm-* && rm -rf $TMPDIR/haste-* && rm -rf $TMPDIR/metro-* && rm -rf node_modules && npm install && rm -rf ios/Pods && cd ios && pod cache clean --all && pod repo update && pod install && ./android/gradlew clean -p ./android/ && rm -rf ios/build && rm -rf ~/Library/Developer/Xcode/DerivedData && npm start -- --reset-cache
@amscotti
amscotti / login.rb
Created November 22, 2011 00:45
Sample of Sinatra authentication
require 'rubygems'
require 'bcrypt'
require 'haml'
require 'sinatra'
enable :sessions
userTable = {}
helpers do
@cowboy-cod3r
cowboy-cod3r / ruby-datetime-format.rb
Created December 14, 2013 15:10
Ruby: Convert the Format of a Date
#!/opt/apps/ruby/ruby/bin/ruby
require 'date'
# The initial date format as a String
my_date = "2013-10-03 21:03:46Z"
# Convert the Date to a DateTime Object
date_obj = DateTime.strptime(my_date,'%Y-%m-%d %H:%M:%S%Z')
# Re-Format the date - returns a String
@matthutchinson
matthutchinson / fakeout.rake
Created February 10, 2010 16:49
fakeout.rake - a simple/configurable rake task that generates some random fake data for the app (using faker) at various sizes
# a simple/configurable rake task that generates some random fake data for the app (using faker) at various sizes
# NOTE: requires the faker or ffaker gem
# sudo gem install faker - http://faker.rubyforge.org
# OR
# sudo gem install ffaker - http://github.com/EmmanuelOga/ffaker
require 'faker'
class Fakeout
# Cleans up branches like:
# if Shopify.rails_next?
# # Rails 5 login
# else
# # Rails 4 login
# end
module RuboCop
module Cop
module ShopifyRails
class RailsNextUnless < Cop