Skip to content

Instantly share code, notes, and snippets.

View abarrak's full-sized avatar

Abdullah Barrak abarrak

View GitHub Profile
@abarrak
abarrak / install.sh
Last active October 3, 2019 21:06
Node.js Install on AWS EC2
yum install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_11.x | sudo -E bash -
yum install nodejs
node -v
npm -v
@abarrak
abarrak / currencies.js
Last active February 8, 2023 19:55
ISO 4217 Currencies List - Javascript
{
'US Dollar (USD)': 'USD',
'Euro (EUR)': 'EUR',
'Pound Sterling (GBP)': 'GBP',
'Australian Dollar (AUD)': 'AUD',
'Afghani (AFN)': 'AFN',
'Lek (ALL)': 'ALL',
'Algerian Dinar (DZD)': 'DZD',
'Kwanza (AOA)': 'AOA',
'East Caribbean Dollar (XCD)': 'XCD',
@abarrak
abarrak / app.component.ts
Last active September 22, 2020 14:21 — forked from pniel-cohen/app.module.ts
Dynamically set page title based on active route in Angular 6+ .. (Corrected & Simplified Version)
import { Component, OnInit } from '@angular/core';
import { TitleService } from './shared/title/title.service';
@Component({
selector: 'ny-app',
templateUrl: './app.component.html',
styles: [],
})
export class AppComponent implements OnInit {
@abarrak
abarrak / callerName.js
Created September 9, 2018 13:35 — forked from irisli/callerName.js
JavaScript get caller in strict mode
"use strict";
var stackTrace = (new Error()).stack; // Only tested in latest FF and Chrome
var callerName = stackTrace.replace(/^Error\s+/, ''); // Sanitize Chrome
callerName = callerName.split("\n")[1]; // 1st item is this, 2nd item is caller
callerName = callerName.replace(/^\s+at Object./, ''); // Sanitize Chrome
callerName = callerName.replace(/ \(.+\)$/, ''); // Sanitize Chrome
callerName = callerName.replace(/\@.+/, ''); // Sanitize Firefox
console.log(callerName)
@abarrak
abarrak / cmd.sh
Created November 2, 2017 10:28 — forked from kelvinn/cmd.sh
Example of using Apache Bench (ab) to POST JSON to an API
# post_loc.txt contains the json you want to post
# -p means to POST it
# -H adds an Auth header (could be Basic or Token)
# -T sets the Content-Type
# -c is concurrent clients
# -n is the number of requests to run in the test
ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/
@abarrak
abarrak / array_to_relation.rb
Created September 7, 2017 08:09 — forked from lappi-lynx/array_to_relation.rb
Rails: Convert array into ActiveRecord Relation object
scope :with_scope, -> { where(id: ARRAY_COLLECTION.map(&:id)) }
@abarrak
abarrak / systme_update_rules.rake
Last active August 27, 2017 20:33
Run rake task after capistrano deployment
namespace :system do
desc 'Update the system rules '
task :update_rules do
on roles(:all) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, 'system:update_rules'
end
end
end
@abarrak
abarrak / flattener.rb
Last active August 10, 2017 14:04
Flattener
# https://stackoverflow.com/a/35963024
module Flattener
def deep_flatten
flatten.map do |item|
case item
when Hash, Array
item.deep_flatten
else
item
@abarrak
abarrak / gist:6db55951fb9ba20a8584fd49eeffa5e3
Created August 6, 2017 08:52 — forked from Andrew-Max/gist:305483febc3c367dbf57
Route lifecycle hooks guide from Ember meetup lightning talk
App.LibraryRoute = App.ApplicationRoute.extend({
activate: function () {
//no longer enter
this._super();
only called once on entering a route.
},
beforeModel: function () {
// any state you want in place before the model is initialized, this is called before any model promises are resolved
// also could be used to conditionally prevent access to a route by throwing transition.abort