Skip to content

Instantly share code, notes, and snippets.

View otkrsk's full-sized avatar

Nick Nuing otkrsk

  • Kuala Lumpur, Malaysia
  • 16:58 (UTC +08:00)
View GitHub Profile
@otkrsk
otkrsk / multiple-ssh-authkeys.md
Last active November 13, 2023 08:40
Add multiple SSH keys to the authorized_keys file to enable SSH authentication when connecting to a server.

Step 1: Generate first ssh key Type the following command to generate your first public and private key on a local workstation. Next provide the required input or accept the defaults. Please do not change the filename and directory location.

workstation 1 $ ssh-keygen -t rsa

Finally, copy your public key to your remote server using scp

Some Docker Commands to Remember

Stop Containers (oneline)

docker stop $(docker ps -a -q)

Remove Containers (oneline)

docker rm $(docker ps -a -q)
@otkrsk
otkrsk / check_last_element.php
Created August 4, 2016 04:42
A snippet of how to check for the last element of the array and perform actions on to it.
/**
* Check if the current array element is the last one, if it is, do something.
*/
$array = array('a' => 1,'b' => 2,'c' => 3);
$lastElement = end($array);
foreach($array as $k => $v) {
echo $v . '<br/>';
if($v == $lastElement) {
// This is the last element. Do as you please.
@otkrsk
otkrsk / scandir_and_sort.php
Created July 20, 2016 08:59
Scan a directory and sort the files according to the last modified date.
<?php
function scan_dir($dir) {
$ignored = array('.', '..', '.svn', '.htaccess');
$files = array();
foreach (scandir($dir) as $file) {
if (in_array($file, $ignored)) continue;
$files[$file] = filemtime($dir . '/' . $file);
}
composer create-project --prefer-dist laravel/laravel [app_name] "5.2.*"
@otkrsk
otkrsk / gist:32dc43c4417973728aead8e7f42fe5ef
Created April 28, 2020 08:13
Copy Screenshot to Clipboard (Mac OS)
Selection (Control (⌃) + Shift (⇧) + Command (⌘) + 4)
Window (Control (⌃) + Shift (⇧) + Command (⌘) + 4 + Spacebar)
from utils.company.helpers import *
email='b.gump@bubbagump.com'
company = get_company_by_email(email)
from employee.models import EmployeeUser
employee_obj = EmployeeUser.objects.filter(email__iexact=email.strip())
# iname is case insensitive
sudo find . -iname "*<search_term>*"
ip addr show
@otkrsk
otkrsk / macos_datetimestamp.sh
Last active February 20, 2020 01:16
Insert a Date Time Stamp Into a File and Append a Date Time Stamp to a Filename (in MacOS).
# insert the date into the file
date "+ %Y-%m-%d %H:%M:%S %z" >> filename.fileext
# append the date into the file
mv filename.fileext $(date +"%Y-%m-%d")_filename.fileext
@otkrsk
otkrsk / js_possible_recursion.md
Last active February 20, 2020 01:15
Possible technique for recursive functions
const createDivs = howMany => {
  if (!howMany) return;
  document.body.insertAdjacentHTML("beforeend", "<div></div>");
  return createDivs(howMany - 1);
};
createDivs(5);
public function thisIsRecursive($x) {