Skip to content

Instantly share code, notes, and snippets.

View diaasami's full-sized avatar

Diaa Sami diaasami

  • 00:05 (UTC -04:00)
View GitHub Profile
@diaasami
diaasami / leetcode-1461.py
Last active November 13, 2023 15:58
LeetCode - 1461. Check If a String Contains All Binary Codes of Size K
class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
num_perms = math.pow(2, k)
substrings_of_len_k = len(s) - k + 1
if substrings_of_len_k < num_perms:
return False
perms = set()
for i in range(k, len(s)+1):
@diaasami
diaasami / convert_control_saves.sh
Created November 13, 2022 21:34
Convert the saves of Remedy's Control game from Epic's format to GOG's
#!/bin/bash
# convert the saves of Remedy's Control game from Epic's format to GOG's
DEST=$(pwd)
if [ $# != "1" ] || ! [ -d "$1" ]; then
echo "A directory must be provided"
exit 1
fi
@diaasami
diaasami / sh
Last active June 1, 2021 13:46
Pause process
# Pause process until a key is pressed
kill -STOP $PID; sh -c "read -n 1 -s -r -p 'Press any key to continue'"; kill -CONT $PID
@diaasami
diaasami / merge_sorted_array.cpp
Last active August 29, 2015 14:22
Leetcode | Merge Sorted Array
// https://leetcode.com/problems/merge-sorted-array/
class Solution
{
public:
void merge(vector<int>& nums1, int m, vector<int>& nums2, int n)
{
int writeIdx = m + n - 1;
int r1 = m - 1;
int r2 = n - 1;
@diaasami
diaasami / gist:4cdc406cb6c59331f3af
Last active August 29, 2015 14:22
Leetcode | Triangle
// https://leetcode.com/problems/triangle/
class Solution
{
public:
int minimumTotal(vector<vector<int> > &triangle)
{
if (triangle.size() == 1)
return triangle[0][0];
for (int i = triangle.size() - 1 - 1; i >= 0; i --)
@diaasami
diaasami / gist:b202f2139b912d6dcb6d
Created June 1, 2015 12:35
Leetcode | Find Minimum in Rotated Sorted Array
class Solution
{
int internal(const vector<int>& nums, int start, int end)
{
if (nums.size() == 1)
return nums[0];
if (end - start == 1)
return min(nums[start], nums[end]);
@diaasami
diaasami / join.cpp
Last active August 29, 2015 14:18
A function similar to Python's join for C++'s vector, probably should be generalized for all containers but I'll leave that for another day.
template <typename T>
string join(const vector<T> &v, const string &sep)
{
ostringstream oss;
for (const T &element: v)
oss << element << sep;
const string out = oss.str();
@diaasami
diaasami / After-install.sh
Created October 8, 2014 23:16
My after-install.sh for Kubuntu
#!/bin/sh
wajig install -y tidy ppa-purge htmldoc dirdiff nmap audacity lm-sensors buffer parallel filelight htop testdisk woof realpath traceroute meld pavumeter p7zip-full
wajig install -y chmsee ipython qtcreator mercurial git idle filezilla chromium-browser krfb rakarrack sox samba zim exuberant-ctags xchat yakuake
wajig install -y pandoc optipng libboost-filesystem binutils-dev gdc scons python-beautifulsoup python-ipdb ssh screen
wajig install -y yudit nemiver kdbg python-pip python-virtualenv skype fmit uget vlc cheese gimp mplayer2 conky gparted colordiff dot graphviz scite pavucontrol tuxguitar
wajig install -y apt-file ack-grep cccc dos2unix powertop
wajig install -y jedit iotop git-gui gitk parted synergy krusader shutter guvcview
wajig install -y synaptic playonlinux ttf-mscorefonts-installer build-essential g++ winff pinta avinfo subversion hardinfo kubuntu-restricted-extras kubuntu-restricted-addons
wajig install -y pitivi smplayer vim-gtk libreoffice keepassx bleachbit handbrake httrack web