Skip to content

Instantly share code, notes, and snippets.

View yasalmasri's full-sized avatar

Yaser Almasri yasalmasri

View GitHub Profile
@yasalmasri
yasalmasri / compound_interest.rb
Created December 13, 2023 21:51
compound_interest.rb
require 'amazing_print'
def interest(amount:, rate:, months:, years:)
a = amount
1.upto(years) do
1.upto(months) do |month|
a += a * rate/months
a += amount
end
end
@yasalmasri
yasalmasri / CurrencyField.swift
Last active September 25, 2022 05:13
Currency Field SwiftUI
//
// ContentView.swift
// CurrencyField
//
// Created by Yaser Almasri on 24/09/22.
//
import SwiftUI
struct ContentView: View {
require 'rest-client'
require 'json'
require 'yaml'
require 'amazing_print'
require 'erb'
require 'csv'
requests = YAML.load_file('requester.yml')
def render(template, vars)
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end

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.
@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 #############################################################################################################
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 / 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
@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 / 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