🤷♂️
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| def binary_search(haystack, needle, start=None, end=None): | |
| start = 0 if not start else start | |
| end = len(haystack) if not end else end | |
| midpoint = math.floor((end - start)/2) + start | |
| # do we match the midpoint or have only one element then we are done | |
| if needle == haystack[midpoint] or len(haystack[start:end]) == 1: | |
| return midpoint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def selection_sort(u, s=[]): | |
| unsorted = list(u) | |
| sorted = [] if not s else s | |
| minimum = None | |
| index = -1 | |
| # loop over every number | |
| for i, item in enumerate(unsorted): | |
| # if the number is less than the minimum or we have no minimum yet set it | |
| if not minimum or item < minimum: | |
| minimum = item |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // if the aws elb is passing host as ip force redirect to domain | |
| // this is for pci fixes | |
| if ($host ~ "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}") { | |
| rewrite ^/(.*) $scheme://www.somewebsite.com/$1 permanent; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # how-to-clean-log-file (http://unix.stackexchange.com/questions/92384/how-to-clean-log-file) | |
| > logfile | |
| cat /dev/null > logfile | |
| dd if=/dev/null of=logfile | |
| truncate logfile --size 0 | |
| # how to get a file octal permissions | |
| stat -c "%a" | |
| # check a makefile for tabs and line endings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CFLAGS = -std=gnu99 -Wall -Wextra -Os -nostdlib -m32 -march=i386 \ | |
| -Wno-unused-function \ | |
| -ffreestanding -fomit-frame-pointer -fwrapv -fno-strict-aliasing \ | |
| -fno-leading-underscore \ | |
| -Wl,--nmagic,-static,-Tmingw.com.ld | |
| all: | |
| gcc $(CFLAGS) -o hello.o hello.c | |
| objcopy -O binary hello.o hello.com |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| from functools import reduce | |
| def bit_count(x): | |
| """ The minimum bits needed to represent a number """ | |
| # return math.ceil(math.log(x + 1) / math.log(2)) | |
| return math.ceil(math.log2(x)) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import requests | |
| import tarfile | |
| def download_github_repo_tar(token, org, repo, branch, to_path): | |
| """ | |
| Downloads a stream tar.gz file from github of a certain organisation/branch/repo | |
| and extracts csv files to tmp directory for parsing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # grep | |
| # -i case insensitive | |
| # -l output file names only | |
| # | |
| # Any line that begins with zero or more spaces | |
| # followed by word "featured" | |
| # followed by zero or more spaces | |
| # followed by ":" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # color pick the homepage | |
| image_filename="public/$(sed -n 's/.*data-color="\([^"]*\).*/\1/p' public/index.html)" | |
| echo "Picking color from : ${image_filename}" | |
| if type "colorific" > /dev/null && [ -f $image_filename ]; then | |
| picked_color=$(echo $image_filename | colorific | cut -d# -f7) | |
| echo "Picked color : ${picked_color}" | |
| sed -i "/^[[:space:]]*.home-blog-bg/,/}$/ s/background-color:.*/background-color: #$picked_color;}/g" public/index.html | |
| else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # image magick extract image from gif | |
| convert Collaboration.gif[4] collaboration-static.gif | |
| # ffmpeg extract image from timestamp | |
| ffmpeg -ss 00:00:04 -i Collaboration.mp4 -vframes 1 collaboration.png | |
| ffmpeg -ss 00:00:12 -i Alerts.mp4 -vframes 1 alerts.png | |
| ffmpeg -ss 00:00:09 -i API.mp4 -vframes 1 api.png | |
| ffmpeg -ss 00:00:07 -i APM.mp4 -vframes 1 apm.png |