Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am stefanosc on github.
* I am stefanosc (https://keybase.io/stefanosc) on keybase.
* I have a public key ASB-DApLRrUNvOaDs4Qs-th7ZUxsfPYfAQePDlEtM58pFwo
To claim this, I am signing this object:
@stefanosc
stefanosc / email.rb
Created March 15, 2016 23:07 — forked from jonmagic/email.rb
A handy Rails model for storing emails with a little logic to let a User have multiple email addresses but a single primary address.
class Email < ActiveRecord::Base
# Nope, it's not RFC compliant. F*** that regex.
# http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html
EmailRegex = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i.freeze
before_validation :strip_spaces
# Public: The email address.
# column :address
@stefanosc
stefanosc / sidekiq
Created March 8, 2016 16:25 — forked from dyerc/sidekiq
Sidekiq init script
#!/bin/bash
# sidekiq Init script for Sidekiq
# chkconfig: 345 100 75
#
# Description: Starts and Stops Sidekiq background worker.
#
# User-specified exit parameters used in this script:
#
# Exit Code 5 - Incorrect User ID
# Exit Code 6 - Directory not found
@stefanosc
stefanosc / redis-server
Last active March 8, 2016 00:05 — forked from tessro/redis-server
A CentOS initscript for Redis
#!/bin/sh
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /etc/redis/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /var/run/redis.pid
@stefanosc
stefanosc / gist:7837759
Last active December 30, 2015 13:49
Rails questions

Answers:

  1. Because data sets can be related through the use of foreign keys
  2. Structrured Query Language, it is a stnadard language to query database to retrieve / store data
  3. Schema aka Strucre view which shows the list of the column names, data view whcih shows the actual data (rows of data)
  4. The Primary key, which is usually the id
  5. The forgeing key is used in rows in a table to join other rows from another table, where the foreign key is the primary key
  6. About ActiveRecord pattern we can say that each table is represented by a Class and each row (of that table) by an instance of that Class. The Class usually also provides attr accessor methods to retrieve / store data in each column
  7. crazy_monkeys - we can also use the very useful 'CrazyMonkey'.tableize method which returns => "crazy_monkeys"
  8. Assuming the following:
@stefanosc
stefanosc / gist:7798465
Last active December 30, 2015 07:49
Questions about Rails Associations

I don’t understand how to use the generated methods as described in the various M:M associations: others
others=(other,other,...)
other_ids
other_ids=(id,id,...)

In the HMT association like in our post-it app project I need to first create the post and then in a second line of code assign it the category / categories. It would not be possible to assign categories in the same line / query where the object is created. Is this correct?

What is the :autosave option on a has_one, belongs_to, has_many, or has_and_belongs_to_many association

@stefanosc
stefanosc / show_env
Created November 17, 2013 08:35 — forked from Beengie/show_env
# Sinatra environment
# Make sure that the link to the "bootstrap.min.js" file is correct in your layout.erb (shown below):
<script src="/vendor/bootstrap/js/bootstrap.min.js"></script>
# Put this in your .erb
<%= show_env %>
# Place constant inside of your main.rb
SHOW_ENVIRONMENT = true
What is HTML? What is CSS? What is Javascript?

HTML is a markup language, used to create HTML pages. CSS stands for cascading style sheet and is a language developed to apply styling properties to HTML documents. Javascript is a so called client side programming language that allows to manipulate a webpage after it has already been rendered in the client browser

What are the major parts of an HTTP request?

request line request headers (optional) blank line request message (optional, may contain POST data)

@stefanosc
stefanosc / ie_ver.js
Created May 31, 2015 00:23
Get IE version with simple JavaScript
//Cool little js function to get version of IE if browser is IE
var ie = (function(){
var undef,
v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');
while (
SELECT e.album_id
FROM jos_hwdms_media as m
LEFT JOIN jos_hwdms_album_map e
ON m.id = e.media_id
LEFT JOIN jos_hwdms_category_map as h
ON m.id = h.element_id