Skip to content

Instantly share code, notes, and snippets.

View mort3za's full-sized avatar
🕸️

Morteza Ziyaeimehr mort3za

🕸️
View GitHub Profile
@mort3za
mort3za / gitlab-bookmarklets.md
Last active March 9, 2023 11:53
Some Gitlab bookmarklets. Use https://www.gibney.org/bookmarklet_editor to convert code to JS and edit it.

Cancel all jobs in column test-run, except those entered in prompt box:

javascript:(function()%7Bconst%20jobs%20%3D%20prompt('Enter%20jobs%2C%20comma%20separated').split('%2C')%3B%0Aconst%20contains%20%3D%20jobs.map(i%3D%3E%60%3Acontains(%22%24%7Bi%7D%22)%60).join()%3B%0A%24(%60%5Bdata-testid%3D%22stage-column%22%5D%3Acontains(%22test-run%22)%20.ci-job-component%3Anot(%24%7Bcontains%7D)%20.cancel%60).trigger('click')%7D)()
@mort3za
mort3za / ssh-key-login.sh
Created December 28, 2022 20:16
How to login to a Linux server with a second ssh key
# generate your new ssh key (e.g. id_rsa_second)
ssh-keygen
# add the public key to server manually (from your host panel) or by:
ssh-copy-id -i ~/.ssh/id_rsa_second.pub root@server_ip_address_here
vim ~/.ssh/config
# enter this code:
Host server_ip_address_here
AddKeysToAgent yes
@mort3za
mort3za / relative-time.ts
Created April 2, 2022 18:02
Relative time with automatic period detection
// example: const mydate = getRelativeTime('Sat Apr 02 2022 14:00:00 GMT');
// console.log(getRelativeTime(mydate);
// output: 4 hr. ago
// (while current time is 18:00)
export const getRelativeTime = (date: string): string => {
const unix = new Date(date).getTime();
type Periods = [string, number][];
const second = 1000;
var suitcase = '25618645791'
@mort3za
mort3za / number-format.twig
Last active October 26, 2021 14:50
Human readable number format in Twig. Example: human_readable(22111, 1) ===> 22.1K
{% macro human_readable(input, fraction) %}
{% spaceless %}
{% set kilo = 1000 %}
{% set mega = kilo * 1000 %}
{% set giga = mega * 1000 %}
{% set tera = giga * 1000 %}
{% if input < kilo %}
{{ input ~ ' B' }}
{% elseif input < mega %}
@mort3za
mort3za / twitter-api-description.md
Last active July 7, 2021 08:40
Summary of what I understood from Twitter API

There is two versions of Twitter API: 1.1 & 2

Version 2 is still in development and subjects to changes. It's better to use v1.1 for now.

There is two versions of OAuth: 1.0a and 2

Version 1.0a is for doing actions on behalf of authenticated user. It needs consumer keys and access tokens.
Version 2 is for doing actions directly from your application. It's suitable to work with public API of twitter, e.g. get a user details.

To work with Oauth v1.0a, there is a nice Node.js package: https://github.com/FeedHive/twitter-api-client/

@mort3za
mort3za / server.js
Created July 3, 2021 06:58 — forked from jeffrafter/server.js
Twitter OAuth with node-oauth for node.js+express
var express = require('express');
var sys = require('sys');
var oauth = require('oauth');
var app = express.createServer();
var _twitterConsumerKey = "YOURTWITTERCONSUMERKEY";
var _twitterConsumerSecret = "YOURTWITTERCONSUMERSECRET";
function consumer() {
@mort3za
mort3za / browserstack-local.txt
Created March 17, 2021 21:59
How to use BrowserStack to see local development page (localhost)?
1. Download the BrowserStack binary from here:
https://www.browserstack.com/docs/live/local-testing
And setup it with your API key.
2. Map bs-local.com to 127.0.0.1 in your hosts file.
3. Build your web application with production environment (If you have a speedy internet connection, you may want to run it with development env)
4. Run your local server (localhost:3000 or similar) and test bs-local.com:3000 works too.