Skip to content

Instantly share code, notes, and snippets.

@luxxi
luxxi / postgresql-data-export.md
Last active August 28, 2015 23:29
Export data from postgresql

Use COPY TO for dump the table data in csv format.

COPY table TO '/tmp/table.csv' DELIMITER ',';

Use the COPY FROM to "paste" it in another table.

COPY another_table FROM '/tmp/table.csv' DELIMITER ',';

@luxxi
luxxi / update_or_create.rb
Last active August 29, 2015 14:17
update_or_create
#Using in single model
def self.update_or_create(attributes)
obj = first || new
obj.assign_attributes(attributes)
obj
end
#User.where(email: "a@b.com").update_or_create(email: "d@e.com")
@luxxi
luxxi / application_controller.rb
Created April 5, 2015 20:40
Can't verify CSRF token authenticity
class ApplicationController < ActionController::Base
protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == 'application/json' }
end
@luxxi
luxxi / user_ip.rb
Created May 10, 2015 16:49
Get user ip on heroku
request.env["HTTP_X_FORWARDED_FOR"].try(:split, ',').try(:first) || request.env["REMOTE_ADDR"]

##Problem I have installed : ruby-2.0.0,postgres-9.2 , now in rails app when I execute:

rake db:create , command I get:

  PG::InvalidParameterValue: ERROR:  new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
  HINT:  Use the same encoding as in the template database, or use template0 as template.
  : CREATE DATABASE "my_db_name" ENCODING = 'unicode'.......

bin/rake:16:in `load'

@luxxi
luxxi / mail.md
Last active September 18, 2015 15:22
Disable mail.app

stop Mail.app from popping-up for every calendar notification.

Simply run the following command in a Terminal window to disable the Mail.app altogether:

sudo mv /Applications/Mail.app/Contents/MacOS/{,_}Mail

If, at any point, you want to go back to using Mail.app simply run the opposite command to revert:

sudo mv /Applications/Mail.app/Contents/MacOS/{_,}Mail

/* ============================================================
CSS Toggle Switch in Sass
source: http://callmenick.com/post/css-toggle-switch-examples
change $cmn-toggle-width for different sizes
============================================================ */
$cmn-toggle-width: 60px;
$cmn-toggle-height: $cmn-toggle-width / 2;
.cmn-toggle {
@luxxi
luxxi / ntfs.md
Last active December 15, 2016 14:30
Enable write to NTFS support

Download osxfuse https://github.com/osxfuse/osxfuse/releases and install it with FUSE for OS X Preference Pane.

Command-line tools and homebrew are needed.

Install ntfs 3g driver.

brew install homebrew/fuse/ntfs-3g

Disable System Integrity Protection. Reboot and hold Command+R.

@luxxi
luxxi / merge.rb
Created January 1, 2017 19:15
Merge multiple files
# Iterates over files and subdirectories in directorie[s] given as arguments
# and adds raw text of those files to merged.txt in the working directory
# where the script is called
# Call like this:
# ruby merge.rb {absolute path portion to delete} {directory to scan} [{directory to scan}]
# For example:
# ruby merge.rb ~Projects/ ~/Projects/stylesheets
# create or open the merged.txt file for writing (in working directory)
#include "OneWire.h"
#define numSensors 8
STARTUP(WiFi.selectAntenna(ANT_AUTO));
// SYSTEM_MODE(SEMI_AUTOMATIC);
OneWire ds = OneWire(D4);
void setup() {}