Skip to content

Instantly share code, notes, and snippets.

@yurifrl
yurifrl / upload_spree.js
Last active August 29, 2015 13:57
upload spree
<style>
.select2-container.select2-container-multi {
width: 100%;
}
</style>
<%= form_for [:admin, @product], :method => :put, :html => {:multipart => true} do |f| %>
<fieldset class="no-border-top">
<%= f.field_container :option_types do %>
<%= f.label :option_type_ids, Spree.t(:option_types) %>
# db/migrate/01_add_custom_admin_roles.rb
class AddCustomAdminRoles < ActiveRecord::Migration
@roles = %w[extra]
def self.up
@roles.each do |r|
Role.create(:name => r)
end
end
class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.timestamps
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_token
@yurifrl
yurifrl / zsh.md
Created July 17, 2014 13:52 — forked from tsabat/zsh.md

installing postgresql 9.3.2 on ubuntu 12.04

$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install postgresql-9.3 postgresql-contrib-9.3

you should succesfully installing postgresql 9.3.2 on your machine.

@yurifrl
yurifrl / gist:ae7e77446b0c1e8e08da
Last active August 29, 2015 14:14
spree upload image via api
conn = Faraday.new(url: 'http://veran.lvh.me:3000/', params: { token: 'ac350077d3066be3d2ca79fd0586e1b1d386b88a5870a1c0' }) do |f|
f.request :multipart
f.request :url_encoded
f.adapter :net_http
end
response = conn.post('api/products/abacate-embalagem-de-1kg/images',{image: {attachment: Faraday::UploadIO.new('./image.jpg', 'image/jpeg')}})
##
// It is important to declare your variables.
(function() {
var foo = 'Hello, world!';
print(foo); //=> Hello, world!
})();
// Because if you don't, the become global variables.
(function() {
@yurifrl
yurifrl / ajax.js
Last active August 29, 2015 14:18
Example of spree CORS ajax
$.ajax({
url: "http://charles.lvh.me/api/products",
method: "GET",
contentType: "application/json; charset=utf-8",
crossDomain: true,
beforeSend: function(xhr){
xhr.setRequestHeader('X-Spree-Token', 'a19d529a7ee5bc807a0b30b83adf998399f3c1804323f349');
xhr.setRequestHeader('Access-Control-Allow-origin', '*');
xhr.setRequestHeader('Access-Control-Allow-Methods', 'PUT, DELETE, GET');
}
// config/environment.js
// This is not for production. But it will get your
// console to stop screaming errors if your messing
// around with ember cli
module.exports = function(environment) {
//lots of stuff
// <Add this chunk>
@yurifrl
yurifrl / bad.js
Last active August 29, 2015 14:23
Javascript Examples
function getQueryParams(qs) {
qs = qs.split("+").join(" ");
var params = {},
tokens,
re = /[?&]?([^=]+)=([^&]*)/g;
while (tokens = re.exec(qs)) {
params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
}