Skip to content

Instantly share code, notes, and snippets.

View MaherSaif's full-sized avatar

Maher Saif MaherSaif

View GitHub Profile
@MaherSaif
MaherSaif / DNS_TO_LOCALHOST.markdown
Created December 25, 2021 16:33 — forked from tinogomes/DNS_TO_LOCALHOST.markdown
Public DNS Pointing to localhost (127.0.0.1)

Available Public Wildcard DNS Domains pointing to localhost (127.0.0.1)

It turns out that some kind hearted people already set up wildcard domains for you already. You can use any domain below and/or any subdomain of these and they currently resolve to 127.0.0.1 but could switch at any time to resolve somewhere else. Here's the list of ones I know about. Let me know if there are more!

  • localhost - It will always works. Do you know why? I hope so.
  • [*.]fuf.me - Managed by @fidian; it will always point to localhost for IPv4 and IPv6
  • [*.]fbi.com - 👏 👏 👏 👏 👏
  • [*.]localtest.me
  • [*.]127-0-0-1.org.uk
  • [*.]vcap.me
@MaherSaif
MaherSaif / node-xcodebuild.ts
Created October 31, 2021 09:39 — forked from thomasvidas/node-xcodebuild.ts
Typescript wrapper for xcodebuild
import { execSync, spawn, SpawnOptions } from 'child_process'
type XCodebuildOptions = {
/**
* Build the project specified by projectname.
* Required if there are multiple project files in the same directory.
*/
project: string,
/**
@MaherSaif
MaherSaif / spinner.rb
Created October 29, 2021 12:51 — forked from clupprich/spinner.rb
Terminal Spinner
%w(⠾ ⠷ ⠯ ⠟ ⠻ ⠽).cycle { |dot| print "\b#{dot}"; sleep 0.1 }
# proxying through apache to a local rails instance, http & https
# apache *.conf file
<VirtualHost *:80>
ServerName psl.localhost
ServerAlias cms.psl.localhost
ServerAlias *.psl.localhost
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
@MaherSaif
MaherSaif / jwt-expiration.md
Created May 28, 2021 04:45 — forked from soulmachine/jwt-expiration.md
How to deal with JWT expiration?

First of all, please note that token expiration and revoking are two different things.

  1. Expiration only happens for web apps, not for native mobile apps, because native apps never expire.
  2. Revoking only happens when (1) uses click the logout button on the website or native Apps;(2) users reset their passwords; (3) users revoke their tokens explicitly in the administration panel.

1. How to hadle JWT expiration

A JWT token that never expires is dangerous if the token is stolen then someone can always access the user's data.

Quoted from JWT RFC:

@MaherSaif
MaherSaif / psql-error-fix.md
Created May 24, 2021 08:53 — forked from AtulKsol/psql-error-fix.md
Solution of psql: FATAL: Peer authentication failed for user “postgres” (or any user)

psql: FATAL: Peer authentication failed for user “postgres” (or any user)

The connection failed because by default psql connects over UNIX sockets using peer authentication, that requires the current UNIX user to have the same user name as psql. So you will have to create the UNIX user postgres and then login as postgres or use sudo -u postgres psql database-name for accessing the database (and psql should not ask for a password).

If you cannot or do not want to create the UNIX user, like if you just want to connect to your database for ad hoc queries, forcing a socket connection using psql --host=localhost --dbname=database-name --username=postgres (as pointed out by @meyerson answer) will solve your immediate problem.

But if you intend to force password authentication over Unix sockets instead of the peer method, try changing the following pg_hba.conf* line:

from

module Api
class NotificationsController < ApiController
before_action :authorize_request
def index
notifications = current_user.notifications.recent
json = NotificationSerializer.new(notifications, is_collection: true).serializable_hash
render json: json
@MaherSaif
MaherSaif / puppies-store.service.ts
Created February 26, 2021 23:02 — forked from seidme/puppies-store.service.ts
An example of simple immutable RxJs store in Angular.
import { Injectable } from '@angular/core';
import { BehaviorSubject, Subject } from 'rxjs';
import { PuppiesModule } from './puppies.module';
import { Puppy } from './puppy.model';
@Injectable({ providedIn: PuppiesModule })
export class PuppiesStoreService {
// Make _puppiesSource private so it's not accessible from the outside,
// expose it as puppies$ observable (read-only) instead.