Skip to content

Instantly share code, notes, and snippets.

View cun3yt's full-sized avatar

Cun3yt cun3yt

View GitHub Profile
@cun3yt
cun3yt / python_cheat.md
Last active May 27, 2023 20:27
Python Cheatsheet

String Ops

s = "abcABCabc"

d = set(s) 	# {'a', 'b', ... }

l = list(s)	# ['a', 'b', ... ]
@cun3yt
cun3yt / qselect.py
Created May 27, 2023 14:29
Quick select to find the k-th largest element
def select_kth_element(nums: List[int], k) -> Optional[int]:
# returns k-th largest element
# 1 <= k <= len(nums)
# if the list is less than size k it returns None
if len(nums) < k or k < 1:
return None
k = len(nums) - k
def quick_select(numbers: List[int], start, end) -> int:
@cun3yt
cun3yt / qsort.py
Created May 27, 2023 10:58
Quick Sort in Python
from typing import List
# sort in place
def qsort(num_list: List[int]):
def _qsort(nums: List[int], start: int, end: int):
if end-start <= 0:
return
pivot = num_list[end]

Keybase proof

I hereby claim:

  • I am cun3yt on github.
  • I am cmertayak (https://keybase.io/cmertayak) on keybase.
  • I have a public key ASBqoaRz9fV3J2Gfgh2jsp9v62wB8Iq_buo7s3541TLplgo

To claim this, I am signing this object:

@cun3yt
cun3yt / on_the_fly_table.sql
Created February 15, 2018 22:38
On-The-Fly Table Treatment in PostgreSQL
select * FROM
(values ('1007163', 2016, 3, 80.09), ('1034758',2013,4,68.85))
T2(person_id_t2, id_yr_t2, id_qtr_t2, score)
@cun3yt
cun3yt / pretty_print_dict.py
Created September 5, 2017 05:18
Pretty Printing Dictionary
my_mapping = {'a': 23, 'b': 42, 'c': 0xc0ffee, 'hede': {'zap': 12}}
print(json.dumps(my_mapping, indent=2, sort_keys=True))
@cun3yt
cun3yt / proper-ssh-file-permission
Created December 28, 2016 15:08
Proper SSH files permission
Typically you want the `.ssh` directory permissions to be `700 (drwx------)` and the public key (`.pub` file) to be `644 (-rw-r--r--)`. Your private key (`id_rsa`) should be `600 (-rw-------)`.
I am asssuming that you mean that you have to enter your system/user password each time, and that previously you did not have to. cdhowie's response is assuming you set a password/passphrase when generating your keys, and if you did then as he says you will have to enter your password every time unless you use an ssh agent.
@cun3yt
cun3yt / crontab.sh
Last active December 28, 2016 14:57
Running a script via cron at a random time, but a certain number of times per day
# Your delay will be between 0 and x, so set this value yourself. This should run every 12 hours, with a random delay.
#
# Make sure this is run using bash.
#
# From [Unix StackExchange](http://unix.stackexchange.com/questions/333197/running-a-script-via-cron-at-a-random-time-but-a-certain-number-of-times-per-da)
0 */12 * * * sleep $((RANDOM%x)) && /bin/sh -c /path/to/script.sh