Skip to content

Instantly share code, notes, and snippets.

@emad-elsaid
emad-elsaid / access_postgresql_with_docker.md
Created November 24, 2018 13:52 — forked from MauricioMoraes/access_postgresql_with_docker.md
Allow Docker Container Access to Host's Postgres Database on linux (ubuntu)

You have to do 2 things in order to allow your container to access your host's postgresql database

  1. Make your postgresql listen to an external ip address
  2. Let this client ip (your docker container) access your postgresql database with a given user

Obs: By "Host" here I mean "the server where docker is running on".

Make your postgresql listen to an external ip address

Find your postgresql.conf (in case you don't know where it is)

$ sudo find / -type f -name postgresql.conf

@emad-elsaid
emad-elsaid / natega.rb
Last active July 12, 2017 19:40 — forked from a7madM/natega.rb
require 'uri'
require 'net/http'
require 'pp'
require 'json'
seat_number = 427_300 # write start seat number
count = 10
(seat_number..seat_number + count).each do |seat|
url = URI('http://natega.youm7.com/Home/GetResultStage1/')
@emad-elsaid
emad-elsaid / stack.js
Last active July 29, 2016 17:14 — forked from khaled0fares/stack.js
Stack implementation in JS using class and constructor
'use strict'
let Stack = function(max){
if(typeof max != 'number' || max == NaN){
throw new Error(max + ' should be a number');
}
var Store = [],
top = 0,
empty = function() { return top === 0; },
class SimpleGit
def self.git(method_name, cmd = nil)
define_method(method_name) do |args|
if cmd
git("#{cmd} #{args}")
else
git("#{method_name} #{args}")
end
end
end
  1. don't use self.method name, just put it in class << self
  2. don't use get_property, use the property name directly get_ and set_ is considered noise in ruby
  3. always add () in function definition with parameters
  4. you should always specify your rescued excpetion class
  5. there are a lot of cryptic lines with implicit logic like flatten[1]
  6. be consistent with methods names "_by(id)"

http://guides.rubyonrails.org/getting_started.html

Rails Guides Getting Started Notes

rails new -h see all app builder switches

File/Folder Purpose

app/ Contains the controllers, models, views and assets for your application. You'll focus on this folder for the remainder of this guide.
config/ Configure your application's runtime rules, routes, database, and more. This is covered in more detail in Configuring Rails Applications
config.ru Rack configuration for Rack based servers used to start the application.

double x = 0;
do
{
Console.WriteLine("the num plz");
x = double.Parse(Console.ReadLine());
if (x > 0)
{
Console.WriteLine(x);
}
else if( x > 0 )
# Chained comparisons in Ruby
# inspired by http://coffeescript.org/#comparisons
# as well as http://refactormycode.com/codes/1284
[:<, :>, :<=, :>=].each do |operator|
[Float, Fixnum, Rational, Comparable].each do |klass|
klass.class_eval do
alias_method "_#{operator}", operator
define_method operator do |rhs|
send("_#{operator}", rhs) && rhs

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation

#!/usr/bin/env ruby
require 'open-uri'
require 'json'
language = 'en'
article = ARGV[0] ||
begin
print 'What do you need to know? : '
URI::encode gets.chomp