Skip to content

Instantly share code, notes, and snippets.

View harssh-sparkway's full-sized avatar

harssh-sparkway

View GitHub Profile
2.0.0p247 :002 > u = User.create!(name:"test")
(0.4ms) BEGIN
SQL (44.1ms) INSERT INTO "users" ("created_at", "name", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["created_at", Mon, 25 Nov 2013 19:35:06 UTC +00:00], ["name", "test"], ["updated_at", Mon, 25 Nov 2013 19:35:06 UTC +00:00]]
(0.8ms) COMMIT
=> #<User id: 1, name: "test", created_at: "2013-11-25 19:35:06", updated_at: "2013-11-25 19:35:06">
2.0.0p247 :003 > u.friends
User Load (2.2ms) SELECT "users".* FROM "users" INNER JOIN "friendships" ON "users"."id" = "friendships"."friend_id" WHERE "friendships"."user_id" = $1 [["user_id", 1]]
=> #<ActiveRecord::Associations::CollectionProxy []>
@harssh-sparkway
harssh-sparkway / import_large_dump
Created April 8, 2014 04:27
Import a large sql dump file to a MySQL database from command line
Import a large sql dump file to a MySQL database from command line
Posted on March 19, 2013 by cmanios
Today I had to import a very large SQL dump file (6 Gb) to a MySQL database using windows command line. If you are using linux it is the same. The process is the following:
Open a command prompt (or shell in Linux) with administrative privilleges
If you are in Windows set character set to unicode. Linux is using UTF-8 by default.
chcp 65001
Connect to a mysql instance using command line
$PATH_TO_MYSQL\mysql.exe -h 192.168.1.1 --port=3306 -u root -p
if you are in localhost you do not need host and port
@harssh-sparkway
harssh-sparkway / port80_bind
Created March 12, 2014 12:35
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
If you get following error, when you try to start nginx…
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
Then it means nginx or some other process is already using port 80.
You can kill it using:
sudo fuser -k 80/tcp
@harssh-sparkway
harssh-sparkway / nginz_cmds
Created March 12, 2014 12:34
The nginx: unrecognized service error means the startup scripts need to be created.
The nginx: unrecognized service error means the startup scripts need to be created.
Fortunately the startup scripts have already been written.
We can fetch them with wget and set them up following these steps:
# Download nginx startup script
wget -O init-deb.sh http://library.linode.com/assets/660-init-deb.sh
# Move the script to the init.d directory & make executable
sudo mv init-deb.sh /etc/init.d/nginx
@harssh-sparkway
harssh-sparkway / async_defer
Created March 10, 2014 08:55
Asynchronous and deferred JavaScript execution explained
Asynchronous and deferred JavaScript execution explained
The HTML <script> element allows you to define when the JavaScript code in your page should start executing. The “async” and “defer” attributes were added to WebKit early September. Firefox has been supporting them quite a while already. Does your browser support the attributes?
Normal execution <script>
-------------------------------
This is the default behavior of the <script> element. Parsing of the HTML code pauses while the script is executing. For slow servers and heavy scripts this means that displaying the webpage will be delayed.
@harssh-sparkway
harssh-sparkway / enable_cors
Created March 7, 2014 12:13
How Do I Enable CORS on My Bucket?
<CORSConfiguration>
<CORSRule>
<AllowedOrigin>http://www.example.com</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
gzip on;
gzip_http_version 1.1;
gzip_disable "msie6";
gzip_vary on;
gzip_min_length 1100;
gzip_buffers 64 8k;
gzip_comp_level 3;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml;
#Instructions
#Add the gems to your Gemfile:
gem 'fog'
gem 'carrierwave'
gem 'rmagick' # optional, for image resizing support
# Add the file './config/initializers/carrierwave.rb' for your CarrierWave configuration:
http://blog.firmhouse.com/fancy-money-entry-for-your-rails-app-with-autonumeric-and-moneyrails
Creating fancy money entry for your Rails app
This week I was working on a client project where we wanted to implement a nice way of entering an amount of money. We wanted to replace a standard text input field with something like this:
Money entry sample
In the resulting implementation, when the user types the amount in the text box it automatically splits thousands and the decimal point.
exporting your repository
Previously there was a tip that covered sharing changes but that included all of your repository’s history.
What if you just want to export a certain commit’s changes? Or just one folder? What if you wanted to make
an archive of the repository for backup?
Fear not, for Git can do all that and more. Thanks to Stack Overflow for providing with some helpful hints to add into this post.
If your need is to just make a quick backup of your repository, doing a git archive will help. So if you wanted to get
zip file packed with your repository’s files: