tony · 2 months ago · Python src: https://devel.tech/tips/n/pIpEnvNh/pipenv/
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
# src: http://www.davidpashley.com/articles/writing-robust-shell-scripts/ | |
# noclobber will not redirect to an existing file | |
if ( set -o noclobber; echo "$$" > "$lockfile") 2> /dev/null; | |
then | |
# we have the lockfile, so be sure to remove it if the script exits early | |
trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT | |
# do our critical stuff |
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 sqlalchemy | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy import Column, Integer, String, ForeignKey | |
from sqlalchemy.orm import sessionmaker, relationship, backref | |
from sqlalchemy.ext.associationproxy import association_proxy | |
import uuid | |
engine = sqlalchemy.create_engine('sqlite:///:memory:') | |
Base = declarative_base() | |
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 socket | |
s = socket.socket(socket.AF_INET, type=socket.SOCK_STREAM) | |
s.bind(('localhost', 0)) | |
address, port = s.getsockname() | |
print("Bound to {} on port {}".format(address, port)) | |
s.close() |
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
#!/bin/bash | |
volumelabel="TimeMachine" | |
dounmount=0 | |
verbose=0 | |
xtrace=0 | |
model=$(sysctl -n hw.model) | |
case "$model" in | |
*MacBook*) |
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 <objc/runtime.h> | |
#import <Foundation/Foundation.h> | |
// src: https://apple.stackexchange.com/questions/80058/lock-screen-command-one-liner/123738#123738 | |
// compile with | |
// clang -framework Foundation main.m -o lockscreen | |
int main () { | |
NSBundle *bundle = [NSBundle bundleWithPath:@"/Applications/Utilities/Keychain Access.app/Contents/Resources/Keychain.menu"]; |
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
# | |
# because there are more than 1500 values for the member attribute, you have to get the paged | |
# results. The attribute will be named member;range=x-y unless it's the remainder, in which | |
# case it will be member;range=x-*. If you search beyond the last result, no entries will be | |
# returned | |
# | |
my @current_member_dns; | |
# define the maximum number of members we will look for |
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-module activedirectory | |
import-csv .\createusers.csv | % {New-ADUser -GivenName $_.GivenName -Surname $_.Surname -Name $_.Name -SamAccountName $_.SamAccountName -Description $_.Description -Path $_.Path -Enabled $True -UserPrincipalName $_.UPN -EmailAddress $_.UPN -AccountPassword (convertto-securestring $_.Password -AsPlainText -force) } | |
## where createusers.csv looks like | |
# Index,GivenName,Surname,Name,SamAccountName,UPN,Description,Path,Enabled,Password,PasswordNeverExpires,ChangePasswordAtLogon | |
# "0001","test","user0001","test user0001","user0001","test.user0001@domain.internal","test user0001","OU=Users,OU=TST,OU=SL1,DC=domain,DC=internal","$True","Orion123_","$True","$False" | |
# "0002","test","user0002","test user0002","user0002","test.user0002@domain.internal","test user0002","OU=Users,OU=TST,OU=SL1,DC=domain,DC=internal","$True","Orion123_","$True","$False" |
src: https://opensource.com/article/17/6/bash-parameter-expansion
$ v='richard'
$ echo ${v:3}
hard
$
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 python | |
# -*- coding: utf-8 -*- | |
import time | |
import os | |
from pid import PidFile, PidFileAlreadyLockedError | |
lockdir = "/tmp/" | |
filename = "mylockfile" | |
lockfile = os.path.join(lockdir, filename + ".pid") |