Skip to content

Instantly share code, notes, and snippets.

@stephenharris
stephenharris / color_luminance.php
Created May 7, 2013 14:19
Lighten or darken a given colour
<?php
/**
* Lightens/darkens a given colour (hex format), returning the altered colour in hex format.7
* @param str $hex Colour as hexadecimal (with or without hash);
* @percent float $percent Decimal ( 0.2 = lighten by 20%(), -0.4 = darken by 40%() )
* @return str Lightened/Darkend colour as hexadecimal (with hash);
*/
function color_luminance( $hex, $percent ) {
// validate hex string
@jonnyjava
jonnyjava / working_effectively_with_legacy_code.md
Created November 4, 2019 21:51
Working effectively with legacy code summary

WORKING EFFECTIVELY WITH LEGACY CODE

To me, legacy code is simply code without tests. I’ve gotten some grief for this definition. What do tests have to do with whether code is bad? To me, the answer is straightforward, and it is a point that I elaborate throughout the book: Code without tests is bad code. It doesn’t matter how well written it is; it doesn’t matter how pretty or object-oriented or well-encapsulated it is. With tests, we can change the behavior of our code quickly and verifiably. Without them, we really don’t know if our code is getting better or worse.

Chapter 1 Changing Software

Four Reasons to Change Software: For simplicity’s sake, let’s look at four primary reasons to change software.

@ccstone
ccstone / Raw_AppleScript_Event_Codes_2006.tsv
Last active May 10, 2024 15:46
Raw AppleScript Event Codes (2006)
Code Terminology Kind Usage Line
$scr scripting additions folder Property of class: domain System Events : Disk-Folder-File Suite 1
%doc music folder Property of class: user domain object System Events : Disk-Folder-File Suite 2
µdoc music folder Enumeration Standard Additions : File Commands 3
ƒhlp help Enumeration Standard Additions : File Commands 4
ƒhlp help folder Enumeration Standard Additions : File Commands 5
ƒlib shared libraries Enumeration Standard Additions : File Commands 6
ƒlib shared libraries folder Enumeration Standard Additions : File Commands 7
ƒmod modem scripts Enumeration Standard Additions : File Commands 8
ƒmod modem scripts folder Enumeration Standard Additions : File Commands 9
@fworks
fworks / install-zsh-windows-git-bash.md
Last active May 10, 2024 15:46
Zsh / Oh-my-zsh on Windows Git Bash
@disler
disler / README.md
Created March 31, 2024 14:34
Use these Prompt Chains to build HIGH QUALITY AI Agents (Agentic Building Blocks)

Setup

  1. Create a new directory with these three files (requirements.txt, main.py, README.md)
  2. python -m venv venv
  3. source venv/bin/activate
  4. pip install -r requirements.txt
  5. python main.py
  6. Update main() to run the example prompt chains
@rollwagen
rollwagen / TTY_reverse_shell.sh
Last active May 10, 2024 15:45
Upgrading simple (reverse-)shells to fully interactive TTYs
#######################################################
# Upgrading simple shells to fully interactive TTYs #
#######################################################
# In reverse shell
$ python -c 'import pty; pty.spawn("/bin/bash")'
Ctrl-Z
# In Kali or elsewhere
$ echo $TERM
@bsun0802
bsun0802 / GeneImage.py
Created January 16, 2022 22:46 — forked from parashardhapola/GeneImage.py
A pure python code to draw gene diagrams with introns and exons and draw markers ('lollipops') at random positions on the gene
import matplotlib.pyplot as plt
"""
MIT License
Copyright (c) [2016] [Parashar Dhapola]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@wassname
wassname / CausalConv2d.py
Last active May 10, 2024 15:43
pytorch Causal Conv2d
from torch.nn.modules.utils import _pair
class CausalConv2d(nn.Conv2d):
def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=None, dilation=1, groups=1, bias=True):
kernel_size = _pair(kernel_size)
stride = _pair(stride)
dilation = _pair(dilation)
if padding is None:
padding = [int((kernel_size[i] -1) * dilation[i]) for i in range(len(kernel_size))]
@acarril
acarril / bootable-win-on-mac.md
Created November 18, 2022 17:49
Create a bootable Windows USB using macOS

For some reason, it is surprisingly hard to create a bootable Windows USB using macOS. These are my steps for doing so, which have worked for me in macOS Monterey (12.6.1) for Windows 10 and 11. After following these steps, you should have a bootable Windows USB drive.

1. Download a Windows disc image (i.e. ISO file)

You can download Windows 10 or Windows 11 directly from Microsoft.

2. Identify your USB drive

After plugging the drive to your machine, identify the name of the USB device using diskutil list, which should return an output like the one below. In my case, the correct disk name is disk2.

@ccstone
ccstone / Create date-string using ICU Date-Time Format Syntax.applescript
Last active May 10, 2024 15:42
Use AppleScriptObjC (ASObjC) to Create a date-string using ICU Date-Time Format Syntax
-------------------------------------------------------------------------------------------
# Auth: Shane Stanley & Christopher Stone
# dCre: 2014/01/19 09:46 +1100
# dMod: 2016/02/24 15:18 -0600
# Appl: AppleScriptObjC
# Task: Create a date-string using ICU Date-Time Format Syntax
# : http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Time-Format-Syntax
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @AppleScriptObjC, @ASObjC, @Shane, @Date, @String