Skip to content

Instantly share code, notes, and snippets.

View yasalmasri's full-sized avatar

Yaser Almasri yasalmasri

View GitHub Profile
@yasalmasri
yasalmasri / point-in-polygon.rb
Last active September 15, 2015 16:07 — forked from kidbrax/point-in-polygon.rb
Check whether a point is within a polygon
def point_in_polygon?(polygonPoints)
return false if self.latitude.blank? or self.longitude.blank?
polygonPoints.each do |point|
point[0] = point[0].to_f
point[1] = point[1].to_f
end
contains_point = false
i = -1
j = polygonPoints.size - 1
@yasalmasri
yasalmasri / web-server.rb
Created February 6, 2016 22:49 — forked from Integralist/web-server.rb
Create basic Web Server in Ruby (using WEBrick)
#!/usr/bin/env ruby
require "webrick"
=begin
WEBrick is a Ruby library that makes it easy to build an HTTP server with Ruby.
It comes with most installations of Ruby by default (it’s part of the standard library),
so you can usually create a basic web/HTTP server with only several lines of code.
The following code creates a generic WEBrick server on the local machine on port 1234,
@yasalmasri
yasalmasri / gist:0cfa5ba6ee42ab594ed9
Created March 5, 2016 18:12 — forked from trcarden/gist:3295935
Rails 3.2.7 SSL Localhost (no red warnings, no apache config)
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@yasalmasri
yasalmasri / imageDownloadExtension.swift
Created July 1, 2016 11:37
Image Download Extension
extension UIImageView {
public func imageFromUrl(urlString: String) {
if let url = NSURL(string: urlString) {
let request = NSURLRequest(URL: url)
let config = NSURLSessionConfiguration.defaultSessionConfiguration()
let session = NSURLSession(configuration: config)
let task = session.dataTaskWithRequest(request, completionHandler: {(data, response, error) in
if let imageData = data as NSData? {
@yasalmasri
yasalmasri / ios10LocalNotifications.swift
Created March 7, 2017 04:57 — forked from stinger/ios10LocalNotifications.swift
Swift 3: ios10 Local notifications
func showPushNotification(title: String, details: String) {
if #available(iOS 10.0, *) {
let interval = TimeInterval(1)
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: interval, repeats: false)
let content = UNMutableNotificationContent()
content.title = title
content.body = details
let req = UNNotificationRequest(identifier: "localPushNotification", content: content, trigger: trigger)
let center = UNUserNotificationCenter.current()
center.getNotificationSettings(completionHandler: { settings in
url = "https://sandbox-api.openpay.mx/v1/#{ENV['OPENPAY_MERCHANT_ID']}/webhooks"
hook = {
url: URL_TO_MY_CONTROLLER,
user: 'USER',
password: 'PASSWORD',
event_types: [
'charge.refunded',
'charge.failed',
'charge.cancelled',
'charge.created',
@yasalmasri
yasalmasri / delete-channel-messages.js
Created June 25, 2018 18:37 — forked from firatkucuk/delete-slack-messages.js
Deletes slack public/private channel messages.
var https = require('https');
// CONFIGURATION #######################################################################################################
var token = 'SLACK TOKEN';
var channel = 'CHANNEL ID';
var privateChannel = false;
var delay = 300; // delay between delete operations in millisecond
// GLOBALS #############################################################################################################

Need to calculate interest for monthly and annually investments:

  • Every month I create an investment with an $XXX amount.
  • All investments are for 1 year with XXX% percentage.
  • Each investment will be recreated with the amount and the gained intereset for example: Year 1: I invest $1000 MXN Year 2: I earn $1100 MXN, I recreate the investment with the amount $1100 MXN and so on for the next years
  • All the monthly investments will be treated the same way.
  • Need to calculate all the interest after XXX date and consider that the last year will only save the monthly amount not investing it.
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
require 'rest-client'
require 'json'
require 'yaml'
require 'amazing_print'
require 'erb'
require 'csv'
requests = YAML.load_file('requester.yml')
def render(template, vars)