This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'uri' | |
require 'benchmark' | |
require 'async' | |
# Function to make a network request | |
def tracking_request(tracking_id) | |
uri = URI.parse("https://jsonplaceholder.typicode.com/posts/#{tracking_id}") | |
response = Net::HTTP.get_response(uri) | |
response.body if response.is_a?(Net::HTTPSuccess) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe TodosController, :type => :controller do | |
describe "GET #index" do | |
#describe "POST #create" do | |
#describe "GET #show" do | |
#describe "PATCH #update" do (or PUT #update) | |
#describe "DELETE #destroy" do | |
#describe "GET #new" do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a skeleton for testing models including examples of validations, callbacks, | |
# scopes, instance & class methods, associations, and more. | |
# Pick and choose what you want, as all models don't NEED to be tested at this depth. | |
# | |
# I'm always eager to hear new tips & suggestions as I'm still new to testing, | |
# so if you have any, please share! | |
# | |
# @kyletcarlson | |
# | |
# This skeleton also assumes you're using the following gems: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("@rails/ujs").start() | |
require("turbolinks").start() | |
require("@rails/activestorage").start() | |
require("channels") | |
require("jquery") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { environment } = require('@rails/webpacker') | |
const webpack = require('webpack') | |
environment.plugins.prepend('Provide', | |
new webpack.ProvidePlugin({ | |
$: 'jquery/src/jquery', | |
jQuery: 'jquery/src/jquery' | |
}) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
candies = 10 | |
no_of_children = 3 | |
children = Array.new(no_of_children, 0) # [0,0,0, ...n] | |
main_index = 0 | |
while(candies > 0) | |
if candies > main_index | |
children[main_index % no_of_children] += main_index + 1 | |
candies = candies - (main_index + 1) | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# paste below content at app/views/spree/admin/products/index.html.erb | |
<% content_for :page_title do %> | |
<%= plural_resource_name(Spree::Product) %> | |
<% end %> | |
<% content_for :page_actions do %> | |
<%= button_link_to Spree.t(:new_product), new_object_url, { class: "btn-success", icon: 'add', id: 'admin_new_product' } %> | |
<% end if can?(:create, Spree::Product) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
class Calculator extends Component { | |
sleep = (milliseconds) => { | |
var start = new Date().getTime(); | |
for (var i = 0; i < 1e7; i++) { | |
if ((new Date().getTime() - start) > milliseconds) { | |
break; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Loading(props) { | |
if (props.error) { | |
return <div>Something went wrong! <button onClick={ props.retry }>Retry</button></div>; | |
} else if (props.timedOut) { | |
return <div>Seems like your net is slow... <button onClick={ props.retry }>Retry</button></div>; | |
} else if (props.pastDelay) { | |
return <div>Loading...</div>; | |
} else { | |
return null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Loadable from 'react-loadable'; | |
function Loading() { | |
return <div>Loading...</div>; | |
} | |
const LoadableBigComponent = Loadable({ | |
loader: () => import('../components/BigComponent'), | |
loading: Loading | |
}); |
NewerOlder