This file contains hidden or 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
``` | |
var jqry = document.createElement('script'); | |
jqry.src = "https://code.jquery.com/jquery-3.3.1.min.js"; | |
document.getElementsByTagName('head')[0].appendChild(jqry); | |
``` | |
Now `$` and all the other good stuff will be available |
This file contains hidden or 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 'csv' | |
file = "#{Rails.root}/public/user_data.csv" | |
products = Product.order(:first_name) | |
headers = ["Product ID", "Name", "Price", "Description"] | |
CSV.open(file, 'w', write_headers: true, headers: headers) do |writer| |
This file contains hidden or 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
**Error:** | |
3.1) Failure/Error: @service = @fastly.create_service(:name => name) | |
Fastly::Error: | |
{"msg":"Bad request","detail":"Exceeding max_total_services: 10"} | |
**Solution** | |
``` | |
$ rails c |
This file contains hidden or 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
FILE SPACING: | |
# double space a file | |
sed G | |
# double space a file which already has blank lines in it. Output file | |
# should contain no more than one blank line between lines of text. | |
sed '/^$/d;G' |
This file contains hidden or 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
brew cask install virtualbox | |
brew install docker docker-machine | |
# create the vm | |
docker-machine create -d virtualbox dev | |
# If seeing: | |
# (dev) No default Boot2Docker ISO found locally, downloading the latest release... | |
# Error with pre-create check: "failure getting a version tag from the Github API response (are you getting rate limited by Github?)" | |
# then: |
This file contains hidden or 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
Using gem aws-sdk for a ror application for uploading images to s3 | |
Uploading images to a fixed bucket with different folders for each object or application. | |
The s3 keeps a limitation on the number of buckets creattion whereas there is no | |
limitation for content inside a bucket. | |
This code will upload image for a user to s3 using aws-sdk gem. The bucket and the image uploaded are made public | |
so that the images uploaded are directly accessible. The input it takes is the image complete path | |
where it is present, folder in which it should be uploaded and user_id for whom it should | |
be uploaded. |
This file contains hidden or 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
use Enumerable#lazy method: avoid endless loop and get just the values u need | |
range = 1..Float::INFINITY | |
p range.lazy.collect { |x| x * x }.first(10) | |
#=> [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] |
This file contains hidden or 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
// Specifically, as data url | |
var saveBlobAsFile = function(fileName, fileContents) { | |
if (typeof(Blob) != 'undefined') { // using Blob | |
var textFileAsBlob = new Blob([fileContents], { | |
type: 'text/plain' | |
}); | |
var downloadLink = document.createElement("a"); | |
downloadLink.download = fileName; | |
if (window.webkitURL != null) { |
This file contains hidden or 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
#!/usr/bin/env ruby | |
# Convert command line | |
# | |
#gm convert -font helvetica -fill white -pointsize 20 -draw "text 500,600 'WALLPAPERZ ARE GOOD'" test.jpg output.jpg | |
# | |
#convert -background transparent -fill white -gravity center -size 1024x200 -font Helvetica -pointsize 20 #caption:"I'm a wallpaper, you know what to do" test.jpg +swap -gravity south -composite output.jpg | |
# | |
# Mogrify command line | |
# |
This file contains hidden or 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
# Note: as you will come to see from looking at these notes, you can only use these properties correctly BEFORE SAVE | |
# If you want to keep track of changes in your model Rails provides "Dirty Objects". E.g. Your model has a 'name' attribute: | |
my_model = MyModel.last | |
my_model.changed? # it returns false | |
# You can Track changes to attributes with my_model.name_changed? accessor | |
my_model.name # returns "Name" |