Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

import Cocoa
let workspace = NSWorkspace.sharedWorkspace()
let activeApps = workspace.runningApplications
for app in activeApps {
if app.active {
let listOptions = CGWindowListOption(arrayLiteral: CGWindowListOption.OptionOnScreenOnly)
let windowList : NSArray = CGWindowListCopyWindowInfo(listOptions, 0)!
for window in windowList {
if (window["kCGWindowOwnerName"] as! String) == app.localizedName {
@stefanocoding
stefanocoding / ubuntu_nvidia_macbook_backlight.md
Created December 18, 2018 23:55
Fix not working backlight when using NVidia propietary driver on Ubuntu 18.04 installed in a Macbook Pro Mid 2014.

After installing the latest NVidia proprietary driver (version 390) using Software & Updates > Additional Drivers, it wasn't possible to change the backlight intensity/brightness of the screen.

The solution that worked for me was to run: sudo setpci -H1 -s 00:01.00 BRIDGE_CONTROL=0. If that solution works for you too, then you may want to make the change permanent. Otherwise, you will have to run the same command each time you power on your Macbook.

Steps to make the change permanent:

  1. Open "Terminal"
  2. Run sudo gedit /etc/rc.local
  3. Enter:
@stefanocoding
stefanocoding / using_jack_and_bitwig_with_intel.md
Last active March 4, 2019 05:58
JACK and Bitwig using the the Intel audio chip. Tested on MacBook Pro 11,3. I get no sound using Alsa and Bitwig with the Intel chip (it works with USB interfaces), so I tried using JACK and it worked. However I had to follow these steps.
  1. Open qjackctl
  2. Click Setup...
  3. Choose "alsa" as the Driver
  4. Choose the analog interface as the Interface (in my case it is hw:PCH,0)
  5. Go to the Advanced tab
  6. Enter the number of inputs in the first textbox next to Channels I/O (2 in my case)
  7. Enter the number of outputs in the second textbox next to Channels I/O (2 in my case)
  8. Click OK
  9. Click Start
  10. Start Bitwig and select "JACK" as the Driver model
@stefanocoding
stefanocoding / highlight_in_scope.py
Created April 9, 2018 15:01
Burp Extension to highlight in the Proxy requests that are in scope
from burp import IBurpExtender
from burp import IProxyListener
class BurpExtender(IBurpExtender, IProxyListener):
def registerExtenderCallbacks(self, callbacks):
self.helpers = callbacks.getHelpers()
self.callbacks = callbacks
callbacks.setExtensionName('Highlight in scope')
callbacks.registerProxyListener(self)
@stefanocoding
stefanocoding / does_email_address_exist.py
Last active June 8, 2019 15:01
Useful Python script to know if an email address exists, based on Inti's Medium post https://medium.com/intigriti/abusing-autoresponders-and-email-bounces-9b1995eb53c2
#!/usr/bin/python3
# Example usage: ./does_email_address_exist.py twitter.com jack
import argparse
from smtplib import SMTP
import dns.resolver
parser = argparse.ArgumentParser()
parser.add_argument('hostname')
parser.add_argument('user')
args = parser.parse_args()
@stefanocoding
stefanocoding / copy_cookie_header.py
Last active October 18, 2019 16:25
This Burp extension adds an item to the context menu - when right-clicking in the request in Proxy or Repeater - to copy the entire "Cookie" header without having to manually select it and press Ctrl+C. It's useful for me when updating session information of tabs in the Repeater for saved projects.

If you need/want to generate an AppImage for Bitwig on a non-Debian Linux:

  1. Download or clone https://github.com/AppImage/pkg2appimage
  2. If you don't have Docker installed, install it
  3. Start Docker
  4. Run ./pkg2appimage-with-docker recipes/Bitwig-Studio.yml (for some reason AppImage already has a recipe for Bitwig)
  5. If it fails, and asks you to set the environment variable ARCH: add the line ENV ARCH=x86_64 (or your architecture) to ./Dockerfile, below DOCKER_BUILD=1

Just in case it's not clear: you have to follow the steps on a terminal, at least step 4.

Solution to copy & paste on the Terminal

flatpak override --user --env=PROTON_NO_ESYNC=1 com.valvesoftware.Steam

Explanation

I tried to play World of Warships on Clear Linux using the flatpak of Steam, but the game never started. So, I ran flatpak run com.valvesoftware.Steam on the Terminal to see if there was any useful information. The error that called my attention was eventfd: Too many open files. I did a google search and found some mention about setting PROTON_NO_ESYNC=1 as an environment variable. So, I ran flatpak override --user --env=PROTON_NO_ESYNC=1 com.valvesoftware.Steam on the Terminal, to set the environment variable PROTON_NO_ESYNC=1 for com.valvesoftware.Steam. I tried again and it worked.

# taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/
# generate server.xml with the following command:
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
# run as follows:
# python simple-https-server.py
# then in your browser, visit:
# https://localhost:443
from http.server import HTTPServer, BaseHTTPRequestHandler
import ssl
@stefanocoding
stefanocoding / ManyToManyInput.md
Last active May 20, 2021 11:02
Using a TextInput for a ManyToManyField on Django 3. Compatible with CreateView.

I needed to use a TextInput in a CreateView for a ManyToManyField and I couldn't find a simple good solution. After looking through the Django source code I noticed that value_from_datadict() is used for ManyToManyField inputs.

In the forms.py file you need something like:

from django.forms import ModelForm, TextInput
from .models import Product

class ManyToManyInput(TextInput):
  def value_from_datadict(self, data, files, name):
 value = data.get(name)