diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..efec321 --- /dev/null +++ b/config.toml @@ -0,0 +1,26 @@ +baseURL = "https://wretched.place" +title = "wretched.place" +theme = "etch" +languageCode = "en-GB" +enableInlineShortcodes = true +pygmentsCodeFences = true +pygmentsUseClasses = true + +[params] + dark = "auto" + highlight = true + +[menu] + [[menu.main]] + identifier = "info" + name = "info" + title = "info" + url = "/info/" + weight = 20 + +[permalinks] + posts = "/:title/" + +[markup.goldmark.renderer] + # Allows HTML in Markdown + unsafe = true diff --git a/content/info/index.md b/content/info/index.md new file mode 100644 index 0000000..f094293 --- /dev/null +++ b/content/info/index.md @@ -0,0 +1,3 @@ +This is a place to document bits and bobs I've been up to that have interested me. +Expect linux and self-hosting tinkering, some novice programming, and maybe the occasional recipe. +I tend to be a fool so take anything written here with a pinch of salt :) diff --git a/content/posts/chess.com-api-and-the-continuing-search-for-en-passant-checkmate.md b/content/posts/chess.com-api-and-the-continuing-search-for-en-passant-checkmate.md new file mode 100644 index 0000000..ae9bf3d --- /dev/null +++ b/content/posts/chess.com-api-and-the-continuing-search-for-en-passant-checkmate.md @@ -0,0 +1,64 @@ +--- +title: chess.com api and the continuing search for en passant checkmate +date: 2022-11-08 +tags: + - chess + - python +draft: false +--- + +Last time we worked out how to get info for all the games played by titled players in a particular month. Today, we have three objectives: + +- Parse this info for the pgn (portable game notation) of each game. +- Write these to a file so we dont have to spend forever downloading them everytime we run the script. +- Devise a way to convert this pgn to a more convenient pythonic format so we can analyse it later. + +First of all, I wrote a little function to get the pgn from the games we downloaded. I added this KeyError exception, but if I'm honest I'm not sure why I was getting this error. Maybe, chess.com doesn't store pgn for all games? I don't know. + +```python +def get_pgns(games): + pgns = [] + for game in games: + try: + pgn = game['pgn'] + pgns.append(pgn) + except KeyError: + print('key error um') + return pgns +``` +Now we have this list of pgns, the next goal is to write them to a file so we theoretically only have to run the stuff from last post once. All the analysis we do on the games can then just be done on the files we save without any talking to the internet required. +```python +def write_pgns(pgns): + with open(month.replace('/','_')+'.csv', 'w') as f: + for pgn in pgns: + f.write(pgn) +``` +Now a pgn looks something like this if it's just printed as a string: + +![image alt text](/image/pgn.webp) + +It contains lots of very useful info but for our purposes of finding en passant checkmates, we would ideally just have a list of each move looking something like this: +```python +moves = [ 'e4', 'e5', 'Bc4', 'Nc6', 'Qh5', 'Nf6', 'Qxf7#'] +``` +We don't need the headers, we don't need the result, and we don't really need the move numbers (these can be deduced from the list indexes). So the challenge is how to convert the pgn to a list; this is the slightly janky solution I came up wtih. +```python +def get_move_list(pgn): + x = pgn.split() + moves = [] + for item in x: + # start fresh list at move 1 - effectively skipping the headers from the list + if item == '1.': + moves = [] + moves.append(item) + # gets rid of clock bits and bobs + elif item[0] == '{' or item[-1] == '}': + pass + else: + moves.append(item) + #remove even indexes from list + #this gets rid of move numbers and the result of the game + del moves[::2] + return moves +``` +I don't doubt it could be done more elegantly but it works I guess. Next time, we'll deal with working out what a list containing an en passant checkmate would look like. diff --git a/content/posts/chess.com-api-and-the-search-for-en-passant-checkmate.md b/content/posts/chess.com-api-and-the-search-for-en-passant-checkmate.md new file mode 100644 index 0000000..bc7b520 --- /dev/null +++ b/content/posts/chess.com-api-and-the-search-for-en-passant-checkmate.md @@ -0,0 +1,53 @@ +--- +title: chess.com api and the search for en passant checkmate +date: 2022-10-26 +tags: + - chess + - python +draft: false +--- + +The chess.com API gives you access to a crazy amount of data on games played on the site. Armed with the knowledge that this data was at my fingertips, I set out to do what any sane person would do: find en passant checkmates. For those not in the know, en passant check mate is kind of the king of moves in chess meme circles. So some sort of python script that identified en passant check mates that occured on the site would be of great value to me. + +First things first, I would need a method of grabbing lots of games from the api. This would be achieved by looking at players on the site and searching their game archives. As I couldn't think of any obvious way to get completely random players on the site, I used the API's lists of all titled players (GM, IM, WIM, etc.) on the site. This is what I came up with -> +```python + def get_archive_urls(titled_urls): + players = [] + for url in titled_urls: + title_list = requests.get(url).json() + title_list = title_list['players'] + players.extend(title_list) + + archive_urls = [] + for username in players: + games = 'https://api.chess.com/pub/player/' + username + '/games/2022/05' + archive_urls.append(games) + return archive_urls + + get_archive_urls([ + 'https://api.chess.com/pub/titled/GM', + 'https://api.chess.com/pub/titled/WGM' + ]) +``` +This function reads a list of urls, gets a list of all the usernames from the api and then inserts this username into a new url which will allow us to access their games from a particular month. I then returns a list of all of these game archive urls. + +The next order of business is taking this list of urls and turning it into a list of games. It looks quite similar to the previous example -> +```python + def grab_games(archive_urls): + games = [] + for url in archive_urls: + archive = requests.get(url).json() + archive_games = archive['games'] + games.extend(archive_games) + return games +``` +Feeding the first function into the second -> +```python + grab_games(get_archive_urls([ + 'https://api.chess.com/pub/titled/GM', + 'https://api.chess.com/pub/titled/WGM' + ])) +``` +We get a very long list of json objects (is that the right phrase? um). Each corresponding to one of games played by GMs and WGMs on chess.com during May of 2022. Come back next time to see what we can do with this very long list. Here's a taster of what the list looks like printed to a terminal - lots of possiblities. + +![image alt text](/image/output.webp) diff --git a/content/posts/configuring-a-minimal-modern-wayland-de-with-home-manager.md b/content/posts/configuring-a-minimal-modern-wayland-de-with-home-manager.md new file mode 100644 index 0000000..6644255 --- /dev/null +++ b/content/posts/configuring-a-minimal-modern-wayland-de-with-home-manager.md @@ -0,0 +1,15 @@ +--- +title: configuring a dynamic, modern, and minimal DIY wayland desktop environment with home-manager +date: 2023-06-25 +tags: + - nixos + - home-manager +draft: true +--- + +### components + +- hyprland (window manager) +- waybar (bar) +- wofi (application launcher) +- mako (notification daemon) diff --git a/content/posts/declarative-firefox-config-with-home-manager-on-nixos.md b/content/posts/declarative-firefox-config-with-home-manager-on-nixos.md new file mode 100644 index 0000000..e09fda2 --- /dev/null +++ b/content/posts/declarative-firefox-config-with-home-manager-on-nixos.md @@ -0,0 +1,82 @@ +--- +title: declarative firefox config with home-manager on nixos +date: 2022-10-02 +tags: + - nixos + - home-manager +draft: false +--- + + +As a man who finds himself reinstalling his OS more than is probably sensible, any opportunity to minimise the post install admin of sorting out all your settings is an attractive one. With that in mind lets take a look at some of the firefox (my current browser of choice) configuration options avilable to you through home-manager. This assumes you have some sort of home-manager setup working. If you do not I found [this](https://github.com/misterio77/nix-starter-configs) friendly githubber's templates to be very helpful. + +First of all you'll need to enable firefox with `programs.firefox.enable = true;` + +### EXTENSIONS + +This will require having the NUR (nix user repo) enabled. But once you do, you can configure any extension you want to be auto installed with something like this: + +```nix +{pkgs, ... }: + let + addons = pkgs.nur.repos.rycee.firefox-addons; + in + { + programs.firefox = { + extensions = with addons; [ + ublock-origin + bitwarden + darkreader + ]; + }; + } +``` +This is the list of [all extensions](https://nur.nix-community.org/repos/rycee/) available in the repo. + +### BOOKMARKS + +Bookmarks can be added per profile. The format for it goes something like this: + +```nix +profiles.james = { + bookmarks = [ + { + name = "best website ever!"; + url = "https://jdysmcl.xyz"; + } + { + name = "best OS ever"; + url = "https://nixos.org"; + } + ]; +}; +``` + +### SETTINGS + +Again, these can be added per profile. Basically, any option you can find in about:config can be added here; this is a selection of potentially useful options I have set: + +```nix +profiles.james = { + settings = { + #newtab stuff + "browser.startup.homepage" = "https://searx.jdysmcl.xyz"; + "browser.newtabpage.enabled" = false; + "browser.newtabpage.activity-stream.enabled" = false; + + #some firefox features i don't really want + "extensions.pocket.enabled" = false; + "extensions.formautofill.creditCards.enabled" = false; + "identity.fxaccounts.enabled" = false; + "signon.rememberSignons" = false; + "browser.search.suggest.enabled" = false; + + #some privacy stuff + "privacy.resistFingerprinting" = true; + "privacy.trackingprotection.enabled" = true; + "dom.security.https_only_mode" = true; + }; +}; +``` + +Of course I am sure there are many more exciting things that could be done here but this is as far as I have got. For all avilable options you can check out [this](https://nix-community.github.io/home-manager/options.html) or alternatively run a `man home-configuration.nix`. Hope this has been helpful :) diff --git a/content/posts/docker-on-nixos.md b/content/posts/docker-on-nixos.md new file mode 100644 index 0000000..7c244e1 --- /dev/null +++ b/content/posts/docker-on-nixos.md @@ -0,0 +1,74 @@ +--- +title: translating docker to nix?! +date: 2023-02-28 +tags: + - docker + - podman + - nixos +draft: false +--- + +In my opinion, there are moments when the convenience of docker and its surrounding ecosystem can't be beat. I've been dabbling in the self hosting world and oftentimes the best maintained packaging option is a docker image. As a result of this I've been playing around with the nixos approach to managing docker containers. + +### nix -> docker compose -> docker run + +To illustrate how to translate a simple example from the world of docker to nix let's have a look at the config for my [searxng](https://docs.searxng.org/) instance. + + +```nix +virtualisation.oci-containers.containers."searxng" = { + autoStart = true; + image = "searxng/searxng"; + volumes = [ + "/srv/searx:/etc/searxng" + ]; + environment = { + BASE_URL = "https://searx.jdysmcl.xyz/"; + INSTANCE_NAME = "go on big boy dont be shy"; + }; + ports = [ "8080:8080" ]; +}; +``` + +Here is the same thing written in a `docker-compose.yml` style format. + +```yaml +services: + searxng: + image: searxng/searxng + volumes: + - /srv/searxng:/etc/searxng + environment: + - BASE_URL=https://searx.jdysmcl.xyz/; + - INSTANCE_NAME=go on big boy dont be shy; + ports: + - "8080:8080" +``` + +Also, this is what it would look like as a simple old `docker run`. + +```sh +$ docker pull searxng/searxng +$ docker run --rm \ + -d -p 8080:8080 \ + -v "/srv/searxng:/etc/searxng" \ + -e "BASE_URL=http://searx.jdysmcl.xyz/" \ + -e "INSTANCE_NAME=go on big boy dont be shy" \ + searxng/searxng +``` + +### bits and bobs + +As you can see, nix very kindly provides you with convenient options for the most essential tasks: mounting volumes, exposing ports, passing environment variables etc. But what about some more niche configurations that aren't exposed in [oci-containers.nix](https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/virtualisation/oci-containers.nix). As far as I can tell, your best bet in these scenarios is `virtualisation.oci-containers.containers..extraOptions`; this lets you pass a list of command line arguments to your docker run command. For example, I had this in my config for a vpn container. + +```nix +virtualisation.oci-containers.containers."vpn".extraOptions = [ + "--cap-add=net_admin" + "--device=/dev/net/tun" + "--network=bridge" +]; +``` + +With a mishmash of these different bits and bobs I was able to do everything that I needed to. It doesn't really open any more doors than docker compose but it's nice to have the option when you're already invested in the nix ecosystem. + +One final note: nix provides the option to choose between docker and podman with `virtualisation.oci-containers.containers.backend`. This defaults to podman. diff --git a/content/posts/elite-dough-philosophy.md b/content/posts/elite-dough-philosophy.md new file mode 100644 index 0000000..bc77399 --- /dev/null +++ b/content/posts/elite-dough-philosophy.md @@ -0,0 +1,43 @@ +--- +title: elite bread dough for lazy boys +date: 2023-01-22 +tags: + - cooking +draft: false +--- + +### INGREDIENTI + +- flour (ideally bread flour but if you don't have it, it's not the end of the world) +- water +- salt +- yeast (i use the little dried packet stuff) + +### RATIOS + +To start measure the weight of flour; this is what we'll work from. You can now work out how much of the other ingredients you need using these ratios: + +- 65% water +- 2% salt +- 0.5% yeast (this amount doesn't particularly matter, as long as it's in this ballpark) + +So if we used 1kg of flour for example, the recipe would look like this: + +- 1000g flour +- 650g water +- 20g salt +- 5g yeast + +### STEPS + +1. Put all the ingredients in a bowl nad mix until the flour is hydrated (you do not need to knead it, just bring it together). +2. Put in the fridge to slowly proof for at least a day. +3. Remove dough as required from the fridge and place in desired baking vessel (you don't have to bake it all at once, I sometimes make a big batch and bake multiple things over the cours of a few days). +4. Proof in vessel for an additional hour or so at room temperature. +5. Bake! + +### SOME HELPFUL RESOURCES + +- [Jim Lahey no knead bread](https://cooking.nytimes.com/recipes/11376-no-knead-bread) +- [Kenji video](https://www.youtube.com/watch?v=uWbl3Sr2y1Y) +- [Ragusea pizza video](https://www.youtube.com/watch?v=o4ABOKdHEUs) diff --git a/content/posts/get-the-thoughts-out-of-your-head-and-into-a-digital-format-with-this-python-journal-script.md b/content/posts/get-the-thoughts-out-of-your-head-and-into-a-digital-format-with-this-python-journal-script.md new file mode 100644 index 0000000..fc213ef --- /dev/null +++ b/content/posts/get-the-thoughts-out-of-your-head-and-into-a-digital-format-with-this-python-journal-script.md @@ -0,0 +1,98 @@ +--- +title: get the thoughts out of your head and into a digital format with this python journal script +date: 2022-12-01 +tags: + - python +draft: false +--- + + +Since getting going with emacs I've gone down the org-mode rabbit hole a little bit. In particular the very nice [org-journal](https://github.com/bastibe/org-journal) package. It basically does what it says on the tin: maintains a journal with a selection of org files. This has been very nice for me. I have often thought about journalling but never really got up a head of steam. Somehow having an entry a keybinding away while I'm doing something with my text editor makes it a lot more palletable. + +Having said all this, I am not completely converted to the church of emacs. Thus, I thoght it would be nice to write a little editor agnostic script which would emulate some of org-journal's features but allow you to use whatever editor you like with markdown. + +### WHAT'S THE TIME? + +First things first, I wrote this little function that would give you a formatted version of your local time. This will be important as a lot of this comes down to dates and times really. It uses python's time module: + +```python +def whats_the_time(format): + return time.strftime(format, time.localtime(time.time())) +``` + +This function takes a string using [python date format codes](https://www.w3schools.com/python/gloss_python_date_format_codes.asp) and spits out the corresponding time. For example, `'%A %d %B, %Y'` would give you Wednesday 12 December, 2022. + +### WHAT TO CALL THE FILES? + +My plan is to have three options for `journal_frequency`: daily, monthly, and yearly. Depending on the value of this variable, each journal file the script creates will represent a day, month, or year. This function gives you a different filename depending on the `journal_frequency` that is set: + +```python +def make_filename(): + if journal_frequency == 'daily': + return whats_the_time('%Y%m%d')+'.md' + + elif journal_frequency == 'monthly': + return whats_the_time('%Y%m')+'.md' + + elif journal_frequency == 'yearly': + return whats_the_time('%Y')+'.md' +``` + +### DO WE NEED A NEW FILE? + +As I could see it, the next problem was determining whether a new journal file was needed. This would only happen if it was the first entry for a day, month, or year. Otherwise, you would simply want to add to the existing file. I came up with this little function using the os module to check if the file that would be created already exists: + +```python +def new_file_required(): + if os.path.exists(os.path.join(journal_dir,make_filename())): + return False + else: + return True +``` + +MAKING FILES AND PUTTING THINGS IN THEM + +Now we have that admin out the way, we're on the home straight. This function creates a file and adds a little title heading at the top using the `title_string` variable. This will be called when we do need a new file: + +```python +def create_file(): + path = os.path.join(journal_dir,make_filename()) + with open(path, 'w') as f: + f.write('# ' + whats_the_time(title_string)) +``` + +This guy adds a subheading wtih the current time as default using the `entry_string` variable. If you had `journal_frequency` set to monthly or yearly though you would likely want to edit this to include bits fo the date. This is called evry time you run the script. + +```python +def write_date(): + path = os.path.join(journal_dir,make_filename()) + with open(path, 'a') as f: + f.write('\n'*2+'### '+ whats_the_time(entry_string)) +``` + +### OPENING A TEXT EDITOR + +Final order of business: how to open the appropriate journal file with the user's chosen editor. For this we can use the subprocess module and [Popen](https://docs.python.org/3/library/subprocess.html#popen-constructor). By default I have this set to get your EDITOR environemnt variable and use that (come to think of it that probs won't work with tui programs) but it could be set to anything. + +```python +def open_editor(): + cmd = [ editor, os.path.join(journal_dir, make_filename()) ] + process = subprocess.Popen(cmd, stdout=subprocess.PIPE) +``` + +Now it's just a matter of sticking all the functions together: + +```python +def main(): + if new_file_required(): + create_file() + write_date() + open_editor() + else: + write_date() + open_editor() + +main() +``` + +As simple as it is, it works reasonalby well as it stands. I would though like to add the ability to customise the file format you want to use so you could have org, plain text, markdown, or whatever. I've got the script set to just run with a keybinding at the moment so it fulfils the immediacy I was enjoying with org-journal. You can find the script [here](https://gitlab.com/robbygozzarder/py) atm. BYEBYE xxx diff --git a/content/posts/getting-started-with-a-barebones-neovim-plugin-in-lua.md b/content/posts/getting-started-with-a-barebones-neovim-plugin-in-lua.md new file mode 100644 index 0000000..101d7c2 --- /dev/null +++ b/content/posts/getting-started-with-a-barebones-neovim-plugin-in-lua.md @@ -0,0 +1,109 @@ +--- +title: so you want to write a neovim plugin with lua +date: 2024-04-06 +tags: + - lua + - neovim +draft: false +--- +I've recently been messing around with writing neovim plugins. +When I initially got going I found it a little tricky to know how to get started. +There's the [official neovim docs](https://neovim.io/doc) which are great; but in my beginner experience exhaustive to the point of slight impenetrability. +Beyond that, the thing I found most useful was simply reading the source of some popular plugins to get an idea of how things worked. +I would recommend sticking to plugins with a smaller scope though. + +As a demostrative MVP (minimal viable plugin) jumping-off-point, I'm going to make a very simple note-taking plugin. +It will provide a command to neovim which when run opens a file titled with the date and time in a specific notes directory. +Vamos. + +This is what you will want your directory structure to look like. + +```bash +├── lua +│ └── note +│ └── init.lua +└── plugin + └── note.vim +``` + +The `plugin/note.vim` file will look like this. + +```vim +command! Note lua require("note").main() +``` + +This creates a custom command `Note` which when run will call a lua function. +Now on to where that function and the meat of the plugin logic will live: the `lua/note/init.lua` file. +With more complex plugins this section will often be split into many files but we've just got one here as it's so simple. + +First things first we create a plugin object. + +```lua +local note = {} +``` + +Then we will define some default options for the plugin in a table. +These are variables you want the user to be able to change when they call the setup function. + +```lua +local defaults = { + note_directory = "~/notes/", + date_format = "%Y-%m-%d %H:%M", + file_extension = ".md", +} +``` + +Next we need the setup function. +This takes the user's options and merges them with our default options. + +```lua +function note.setup(user_options) + options = vim.tbl_deep_extend("force", defaults, user_options or {}) +end +``` + +This is the main function where the magic happens. + +```lua +function note.main() + local dir = options.note_directory + local name = os.date(options.date_format) + local ext = options.file_extension + local filename = string.format("%s%s%s", dir, name, ext) + local command = string.format("edit %s", filename) + vim.api.nvim_command(command) +end +``` + +Finally we return the plugin obect. + +```lua +return note +``` + +At this point you should have a working plugin :) +As a little coda, this is how you can use your fancy new plugin using [lazy.nvim](https://github.com/folke/lazy.nvim/). + +```lua +require("lazy").setup({ + { + -- local + dir = "~/neovim-note-plugin", + + -- github + -- "me/neovim-note-plugin", + + -- alternative non github hosting + -- url = "https://git.example.com/me/neovim note-plugin", + + config = fucntion() + require("note").setup({ + file_extension = ".org", + }) + end, + + } +}) +``` + +Hope you've enjoyed. diff --git a/content/posts/lowkey-emacs-setup.md b/content/posts/lowkey-emacs-setup.md new file mode 100644 index 0000000..3da646f --- /dev/null +++ b/content/posts/lowkey-emacs-setup.md @@ -0,0 +1,127 @@ +--- +title: lowkey emacs setup +date: 2022-11-18 +tags: + - emacs +draft: false +--- + + +About a month ago I was a little bored and thought I'd give emacs a go. There's something fun about trying out these mythical pieces of software that have been around forever; kind of like watching The Godfather for the first time. Like many extensible, super configurable programs, emacs seems kind of impenetrable at first glance. I tried doing the tutorial but kind of glazed over after a while with the endless stream of C-a C-b C-c. There's also the quite jarring default theme which wasn't vibing with the lovely screenshots I had seen on the internet. Anyway, after quite a bit of fiddling I've landed on a simple little setup that I've been quite enjoying. Here are a few little pointers to hopefully ease you in. + +### AESTHETIC NICETIES + +First things first, assuming you're on linux emacs is configured with a file at `~/.emacs.d/init.el`. As a terrible aesthete, the first thing I was worried about was changing the theme. This can be achieved with `M-x load-theme`; if you want the setting to persist though you can add this to you init.el: + +```lisp +(load-theme 'misterioso t) +``` + +There are a few themes out of the box but if you're looking for some more I would recomment the doom-themes package. Speaking of packages, emacs has a built in package-manager that installs packages from the Emacs Lisp Package Archive (GNU ELPA); I unfortunately know very little about this as I've been using nix to manage my emacs packages. + +Anyway we've got a theme, how about a custom startup message for our initial buffer: + +```lisp +(setq inhibit-startup-message t + inhibit-startup-echo-area-message t + initial-scratch-message + ";;oh how i adore to edit text with emacs!") +``` + +Maybe you dont want those big old cumbersome toolbars cluttering up your screen: + +```lisp +(scroll-bar-mode -1) +(tool-bar-mode -1) +(menu-bar-mode -1) +``` + +Perhaps some line highlighting and numbering: + +```lisp +;;line numbering +(global-display-line-numbers-mode) +(setq display-line-numbers-type 'relative) + +;;line higlight +(global-hl-line-mode t) +``` + +Custom font? + +```lisp +(setq default-frame-alist '((font . "agave Nerd Font 14"))) +``` + +### CUSTOM KEYBINDINGS AND EVIL +I don't know if it's just sunk cost fallacy or what but having gone to the trouble of learning to some extent how vim works, I kind of feel incomplete without vim keybindings now. Fortunately, emacs has evil mode which effectively emulates vim modal editing in emacs. To configure evil in our init.el we'll use use-package. This is a macro which - to my understanding - talks to your package manager allowing you to configure installed packages in a nice neat efficient manner. To enable it, add this to your init.el: + +```lisp +(eval-when-compile + (require 'use-package)) +``` + +These are the keybindings that I currently have going; nothing too crazy just a few simple things: + +```lisp +(use-package evil + :config + (evil-mode 1) + (evil-select-search-module 'evil-search-module 'evil-search) + + ;;manage panes + (define-key evil-normal-state-map (kbd "M-s") 'evil-window-split) + (define-key evil-normal-state-map (kbd "M-v") 'evil-window-vsplit) + + (define-key evil-normal-state-map (kbd "M-h") 'evil-window-left) + (define-key evil-normal-state-map (kbd "M-j") 'evil-window-down) + (define-key evil-normal-state-map (kbd "M-k") 'evil-window-up) + (define-key evil-normal-state-map (kbd "M-l") 'evil-window-right) + + ;;get files open quick + (define-key evil-normal-state-map (kbd "M-f") 'find-file) + (define-key evil-normal-state-map (kbd "M-b") 'dired-jump) + + ;;terminal + (define-key evil-normal-state-map (kbd "M-t") 'ansi-term) + + ;;nav buffers + (define-key evil-normal-state-map (kbd "M-,") (kbd "C-x ")) + (define-key evil-normal-state-map (kbd "M-.") (kbd "C-x ")) + ) +``` + +### SOME FRIEDNLY IDE FEATURES YOU MAY LIKE + + I don't know about you but having used vscode here and there I've become accustomed to a lot of these little IDE crutches (completion, autopair and the like) and now when I don't have thme I feel a little sad. Emacs has it covered though as long as you're happy with installing some additional stuff. Auto-completion? Try company: + +```lisp +;; enable company in all buffers +(add-hook 'after-init-hook 'global-company-mode) +(use-package company + :commands company-tng-configure-default + :custom + ;; delay to start completion + (company-idle-delay 0) + ;; nb of chars before triggering completion + (company-minimum-prefix-length 1) +``` + +You want the nice little autopair brackets? + +```lisp +(use-package flex-autopair + :config + (flex-autopair-mode 1)) +``` + +Clever commenting? + +```lisp +(use-package smart-comment + :bind ("M-c" . smart-comment)) +``` + +Here's a little pic of the current setup :) + +![emacs](/image/emacs.png) diff --git a/content/posts/making-nix-colors-talk-to-neovim.md b/content/posts/making-nix-colors-talk-to-neovim.md new file mode 100644 index 0000000..955cfb0 --- /dev/null +++ b/content/posts/making-nix-colors-talk-to-neovim.md @@ -0,0 +1,60 @@ +--- +title: making nix-colors talk to neovim +date: 2023-08-18 +tags: + - nix-colors + - neovim + - nixos + - home-manager +draft: false +--- + +I recently started fiddling around with home-managerifying my neovim config. +After moving across most of my stuff I came across the problem of how to hook things up with with [nix-colors](https://github.com/misterio77/nix-colors) so that my neovim theme would follow color changes in home-manager. + +Luckily, I came across [this](https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-base16.md) handy little plugin from the lovely [mini.nvim](https://github.com/echasnovski/mini.nvim) suite of plugins which lets you create your own theme with your custom colors. + +Beneath is a little snippet of how you could make it all happen. + +```nix +{ inputs, pkgs, ... }: { + imports = [ + inputs.nix-colors.homeManagerModules.default + ]; + scheme = inputs.nix-colors.schemes.onedark; + programs.neovim = { + enable = true; + plugins = with pkgs.vimPlugins; [ + { + plugin = mini-nvim; + config = '' + lua << END + require('mini.base16').setup({ + palette = { + base00 = '#${scheme.colors.base00}', + base01 = '#${scheme.colors.base01}', + base02 = '#${scheme.colors.base02}', + base03 = '#${scheme.colors.base03}', + base04 = '#${scheme.colors.base04}', + base05 = '#${scheme.colors.base05}', + base06 = '#${scheme.colors.base06}', + base07 = '#${scheme.colors.base07}', + base08 = '#${scheme.colors.base08}', + base09 = '#${scheme.colors.base09}', + base0A = '#${scheme.colors.base0A}', + base0B = '#${scheme.colors.base0B}', + base0C = '#${scheme.colors.base0C}', + base0D = '#${scheme.colors.base0D}', + base0E = '#${scheme.colors.base0E}', + base0F = '#${scheme.colors.base0F}', + }, + }) + END + ''; + } + ]; + }; +} +``` + +Happy theming! diff --git a/content/posts/multi-user-qtile-fiddling.md b/content/posts/multi-user-qtile-fiddling.md new file mode 100644 index 0000000..a393f4e --- /dev/null +++ b/content/posts/multi-user-qtile-fiddling.md @@ -0,0 +1,112 @@ +--- +title: multi user qtile fiddling +date: 2022-12-20 +tags: + - qtile + - python + - nixos + - home-manager +draft: false +--- + + +This post is going to detail how I solved a very particular problem I had created for myself. First, a quick description of the problem. I use home-manager on nixos to declaratively configure what happens on my computer. In the cases where home-manager does not expose sufficient configuration options for my liking (qtile for example), I instead link a configuration file from my nixos config to where it belongs in my home using `xdg.configFile`. This is what I do with my qtile `config.py`. I use qtile on my desktop and laptop but I dont want an identical setup on the two machines. I have jumped through many different slightly silly hoops in my nixos config sort of solving this problem until the other day it occured to me this could all be achieved with my python in my qtile config. + + +### THE NUB OF THE PROBLEM + +I basically just want the config to work out which computer it''s on and then change some things accordingly. This can be achieved by getting the hostname with the socket module: + +```python +if socket.gethostname() == 'baron': + # some stuff i want to happen on my desktop +elif socket.gethostname() == 'countess': + # some stuff i want to happen on my laptop +``` + +There are three main things that I like to differ between my two computers: + +- widgets on my bar (I don't need brightness and battery on my desktop) +- keybindings +- programs to autostart + +### WIDGETS + +My current solution for this is to define to separate lists of widgets and then point to each one when I make my bar for each computer. This isn't perfect; it would be nice to have a list of all common widgets and then add to that with the unique ones. I haven't worked out a way to add the additional widgets without just plopping them all at the end of the bar which isn't necessarily where I want them (thinking about this now I think I might be able to use the insert method with a little for loop). + +```python +countess_widgets = [ + # all the great widgets i want on my laptop +] + +screens = [ + Screen( + top = bar.Bar( + widgets = countess_widgets + ), + ), +] +``` + + + +### KEYBINDINGS + +For keybindings I use extend to add some additional bindings to my global ones. This is mainly useful for the ones I use to change brightness on my laptop. + +```python +countess_keys = [ + Key([m], 'Up', + lazy.spawn('light -A 5'), + desc='backlight up' + ), + Key([m], 'Down', + lazy.spawn('light -U 5'), + desc='backlight down' + ), + ] + +keys.extend(countess_keys) +``` + +You could even change a specific global binding on one computer if you knew its index in the list: + +```python +keys[420] = Key([m], 'd', + lazy.spawn('dmenu_run'), + desc = 'dmenu' + ) +``` + +### AUTOSTART + +Finally, I use this to autostart different programs which I want to change on each computer. For example I use an xrandr command to make sure my desktop monitor is at 144hz. It looks like this: + +```python +@hook.subscribe.startup_once +def autostart(): + processes = [ + [ + 'feh', + '--bg-scale', + '/home/james/pics/wallpapers/beaut.jpg' + ], + [ + 'xrandr', + '--output', + 'DisplayPort2', + '--primary', + '--mode', + '1920x1080', + '--rate', + '143.85' + ] + ] + for p in processes: + subprocess.Popen(p) +``` + +Of course, there are many ways that this could all be achievd but I think it's quite neat having it all in my one qtile config. That's about it for today. lots of love x + + + diff --git a/content/posts/nix-colors.md b/content/posts/nix-colors.md new file mode 100644 index 0000000..049f5ee --- /dev/null +++ b/content/posts/nix-colors.md @@ -0,0 +1,125 @@ +--- +title: theming nirvana +date: 2023-03-13 +tags: + - nixos + - home-manager + - nix-colors +draft: false +--- + +As I fall deeper and deeper down the nixos rabbit hole, I find myself becoming more and more obsessed with controlling every little thing on my computers declaratively. It starts with: 'oh this is cool I can specify which desktop environment to use in my configuration.nix'. Next thing you know you've discovered [home-manager](https://github.com/nix-community/home-manager) and every program on every linux system you use needs to be controlled in your nix-config. Of course this slightly insane approach has its downsides; it also opens some doors though. + +[Nix-colors](https://sr.ht/~misterio/nix-colors/) lets you dyanmically change the theming of programs controlled in your nix config. So when you want to change the color of everything and have it match and all be pretty lol, you are able to do so with one word as opposed to poring over everything changing each individual color. For a certain type of person, this is very nice! + +### how to make it work + +This will be a quick rundown of how I've got things set up; this is basically just a rehash of [this](https://sr.ht/~misterio/nix-colors/#setup). + +First of all, you need to add nix-colors to your flake inputs and then point home-manager in its direction. The relevant parts of my `flake.nix` look something like this. + +```nix +{ + inputs = { + nix-colors.url = "github:misterio77/nix-colors"; + }; + homeConfigurations = { + "randy@computer" = home-manager.lib.homeManagerConfiguration { + extraSpecialArgs = { inherit nix-colors; }; + }; +} +``` + +Then you can import the module into your home-manager config, specify a scheme ([available schemes here](https://github.com/tinted-theming/base16-schemes)), and get to theming. + +Here's a simple example where I make my dunst notifications follow the everforest theme. + +```nix +{ pkgs, config, nix-colors, ... }: { + + imports = [ + nix-colors.homeManagerModule + ]; + + colorScheme = nix-colors.colorSchemes.everforest; + + services.dunst = { + enable = true; + urgency_normal = { + background = "#${config.colorScheme.colors.base01}"; + foreground = "#${config.colorScheme.colors.base05}"; + }; + }; +} +``` + +### a couple of additional tips and tricks + +First tip and trick: generate and dynamically alter gtk themes depending on current nix-colors theme. + +```nix +{ config, pkgs, inputs, ... }: + +let + inherit (inputs.nix-colors.lib-contrib { inherit pkgs; }) gtkThemeFromScheme; +in rec { + gtk = { + enable = true; + theme = { + name = "${config.colorScheme.slug}"; + package = gtkThemeFromScheme { scheme = config.colorScheme; }; + }; + }; + + services.xsettingsd = { + enable = true; + settings = { + "Net/ThemeName" = "${gtk.theme.name}"; + "Net/IconThemeName" = "${gtk.iconTheme.name}"; + }; + }; +} + +``` + +Second tip and trick: if you're not using nix to configure everything you can still pass your colors across in the relevant format with `home.file`. I do this for qtile. + +```nix +{config, pkgs, ... }: + let + c = config.colorScheme.colors; + in +{ + home.file = { + ".config/qtile/colors.py" = { + text = '' + scheme = { + 'yellow': "#${c.base0A}", + 'orange': "#${c.base09}", + 'red': "#${c.base0F}", + 'magenta': "#${c.base08}", + 'violet': "#${c.base0E}", + 'blue': "#${c.base0D}", + 'cyan': "#${c.base0C}", + 'green': "#${c.base0B}", + } + ''; + }; + }; +} +``` + +You can then import the colors into your `config.py` and use them as you see fit. + +```python +from colors import scheme + +layouts = [ + layout.MonadTall( + border_normal = scheme['yellow'], + border_focus = scheme['green'], + ), +] +``` + +That's it for today. Thank you to the [hero](https://github.com/Misterio77) that made this. diff --git a/content/posts/podcast-setup-for-broke-boys-whose-trash-phone-cant-hack-modern-apps.md b/content/posts/podcast-setup-for-broke-boys-whose-trash-phone-cant-hack-modern-apps.md new file mode 100644 index 0000000..94653a3 --- /dev/null +++ b/content/posts/podcast-setup-for-broke-boys-whose-trash-phone-cant-hack-modern-apps.md @@ -0,0 +1,127 @@ +--- +title: podcast setup for broke boys whose trash phone cant hack modern apps +date: 2023-01-24 +tags: + - python +draft: false +--- + +I have an old sad android phone with 2GB of ram which nowadays seems to struggle with anything but the most lightweight apps. As a result of this I have been 'podcast-player-hopping' without success for the last couple of months trying to find something which doesn't nuke my phone whenever I use it. In a moment of desperation it occured to me that a creative solution might be required. The gameplan was this: + +- write python script to download podcasts +- set up cron job on my server to run script every couple of hours +- sync podcasts across my devices using the lovely [syncthing](https://syncthing.net/) +- listen to podcasts using vlc which my phone loves + +For the python script I used the lovely [feedparser](https://feedparser.readthedocs.io/en/latest/introduction.html) module for easy talking to my rss feeds. + +### WHERE THE PODCASTS GO + +First thing I would want my script to do is create a subdirectory of my main podcast directory for each individual podcast. After plopping all my feeds in a list like this: + +```python +rss_urls = [ + 'https://anchor.fm/s/1311c8b8/podcast/rss', + 'https://feeds.acast.com/public/shows/5e7b777ba085cbe7192b0607' +] +``` + +I wrote a little function that would parse each of these feeds get its name, and make a directory if one does not already exist. + +```python +def create_dirs(): + for url in rss_urls: + f = feedparser.parse(url) + feed_name = f['feed']['title'] + current_feeds = os.listdir(pod_dir) + + if feed_name not in current_feeds: + os.makedirs(pod_dir + feed_name) +``` + +### DOWNLOADING + +With this sorted I now turned to the actual downloading of podcasts. This function parses each rss feed, filters it for entries from the last week, then grabs a title and a url for the audio file. These are stuck together into a list of lists with each list representing a separate entry. + +```python +def get_pods(): + global feed_info + feed_info = [] + for url in rss_urls: + f = feedparser.parse(url) + for pod in f.entries: + if time.time() - time.mktime(pod.published_parsed) < (86400*7): + feed_name = f.feed.title + pod_name = pod.title + pod_dl = pod.enclosures[0].href + pod_info = [ + feed_name, + pod_name, + pod_dl + ] + feed_info.append(pod_info) + return feed_info +``` + +This next function looks at all the podcast subdirectories and returns a list of all the podcasts I already have downloaded. This can be used when downloading to only get new podcasts. + +```python +def get_downloads(): + downloads = [] + pods = os.listdir(pod_dir) + + for dir in pods: + if os.path.isdir(pod_dir + dir): + for file in os.listdir(pod_dir + dir): + downloads.append(file) + return downloads +``` + +Now for the actual getting of the audio files. Here we use requests to make a request to the audio file url and write the content to the relevant directory. I also append a .mp3 to the filenames so they play nice with media players. + +```python +def download(): + a = get_pods() + for pod in a: + b = get_downloads() + if pod[1]+'.mp3' not in b: + try: + dl = requests.get(pod[2]) + except: + print('Download Error') + + with open(pod_dir + pod[0] + '/' + pod[1] + '.mp3', 'wb') as file: + file.write(dl.content) +``` + +### PRUNING + +As it stands, the script does downloading great. The only thing we need is some kind of automatic deletion so my phone doesnt get clogged up with old podcasts. This function checks for files which were created over a week ago and deletes the offenders. + +```python +def trim(): + for dir in os.listdir(pod_dir): + if os.path.isdir(pod_dir + dir): + pods = os.listdir(pod_dir + dir) + for pod in pods: + st = os.stat(pod_dir + dir + '/' + pod) + mtime=st.st_mtime + if time.time() - mtime > (86400*trim_age): + os.remove(pod_dir + dir + '/' + pod) +``` + +The last thing is to call the functions: + +```python +create_dirs() +download() +trim() +``` + +Of course this slightly ramshackle approach is certainly not for everyone lol but as it stands it's working quite nicely for me. Lots of love and happy listening :) + + + + + + diff --git a/content/posts/rudimentary-local-scrobbling-with-bash.md b/content/posts/rudimentary-local-scrobbling-with-bash.md new file mode 100644 index 0000000..ad0d3fc --- /dev/null +++ b/content/posts/rudimentary-local-scrobbling-with-bash.md @@ -0,0 +1,58 @@ +--- +title: rudimentary local scrobbling with bash +date: 2022-09-13 +tags: + - music + - bash +draft: false +--- + + +There are lots of music players on linux. I have used lots of them, I quite like some of them. But for some reason I decided I wanted more. With this in mind, over the past few months I have been constructing a sprawling ecosystem of bash scripts all geared towards delivering a customised listening experience tailored perfectly to my every need. In short, the setup uses a simple dmenu file manager to browse my local files and mpv to play them. Today I'll be talking specifically about my setup for recording the albums I've been listening to. + +### LET'S GET DOWN TO BUSINESS + +Whenever I select a file to be played with my script I am effectively selecting a path to a file or a path to a directory with files in it which is then fed to mpv. For example, if I'm playing the classic album Lemonade by Beyonce it would look like this: + +`/home/randy/music/Beyonce/Lemonade/` + +To append this path to a file called scrobble while removing the first three directories (or the first 18 characters) rather inelegantly: + +```bash +printf "%s" "$selected_path" | cut -c 18- >> scrobble +``` + +As new paths are appended to the file, this will will result in a scrobble file made up of three columns: the first for artists, the second for albums, and the third for songs. + +```bash +Abdullah Ibrahim/South Africa +Darkside/Psychic +SOPHIE/OIL OF EVERY PEARL'S UN-INSIDES +Nicolas Jaar/Space Is Only Noise/2 Colomb.flac +Townes Van Zandt +``` + +As you can see here, unless you only play music song by song, not all columns will always be populated. Now we have a file that contains this information we can do stuff to it. For example, to show our listening history and display it in columns with some pretty labels: + +```bash +tac scrobble | column -t -s "/" -N " ,artist,album,track" +``` + +Maybe you only want the last ten things you listened to: + +```bash +tail -n 10 scrobble | column -t -s "/" -N " ,artist,album,song" +``` + +To find our most played atrists it's a little more complicated. We can use awk to extract the artist column and remove all duplicate entries with sort -u to get a list of all played artists to iterate over. Then for each unique artist we grep for instances of them in the artist column and append that number of instances and the artist to a temporary file. This can then displayed as you see fit: + +```bash +for album in $(awk -F/ '{ print $2 }' scrobble | sort -u) + do + echo "'$album'/"$(awk -F/ '{ print $2 }' "$scrob_file" | grep $album | wc -l)"" >> temp + done +``` + +So these are just a few examples; the real point is once you have that file of three columns the world is your oyster. You could probably even use something a little less cumbersome such as python. + +Finally, disclaimer: I am a bash amateur so I hope nothing you've seen here was too upsetting. Lots of love x diff --git a/content/posts/running-headscale-on-nixos.md b/content/posts/running-headscale-on-nixos.md new file mode 100644 index 0000000..6559c65 --- /dev/null +++ b/content/posts/running-headscale-on-nixos.md @@ -0,0 +1,9 @@ +--- +title: adventures in running headscale on nixos +date: 2024-06-25 +tags: + - nixos +draft: true +--- + + diff --git a/content/posts/setting-up-a-lean-mean-hugo-blogging-theme.md b/content/posts/setting-up-a-lean-mean-hugo-blogging-theme.md new file mode 100644 index 0000000..fff454c --- /dev/null +++ b/content/posts/setting-up-a-lean-mean-hugo-blogging-theme.md @@ -0,0 +1,87 @@ +--- +title: setting up a lean mean hugo blogging theme +date: 2022-11-10 +tags: + - hugo +draft: false +--- + + +When I first started messing around with hugo, I found the whole thing slihtly mystifying. I downloaded a theme like they asked me, edited the config file to try and customise things a little and quickly broke everything. To be fair, this was mainly due to my tinkering instinct to fly to close to the sun. But anyway, the point at which I started to really appreciate the power of hugo was when I tried to make my own - admittedly less feautureful - theme. This selection of tips and tricks will assume that you've just run something like `hugo new site lovely-new-website`, entered the new directory with `cd lovely-new-website` and you've got a selection of mostly empty directories looking something like this. +```bash +. +├── archetypes +│   └── default.md +├── config.toml +├── content +├── data +├── layouts +├── public +├── static +└── themes +``` +Our first concern will be getting a barebones theme template that can be customised to our liking. I would recommend [this](https://github.com/ericmurphyxyz/hugo-starter-theme) guy which I used to get up and running. You could also check out [my theme](https://gitlab.com/robbygozzarder/mcl) which I'm using on this site that is also very simple (as you can probably see from the website lol). Once you've got a theme with (I'm using mine as an example) `git clone https://gitlab.com/robbygozzarder/mcl` and placed it in the themes directory you'll need to adjust your config.toml file to point it to this theme. +```toml +theme="mcl" +``` +The directory structure of your new theme will look something like this: +```bash +. +└── mcl + ├── archetypes + │   └── default.md + ├── layouts + │   ├── 404.html + │   ├── _default + │   │   ├── list.html + │   │   └── single.html + │   ├── index.html + │   └── partials + │   ├── footer.html + │   ├── header.html + │   └── nav.html + ├── README.md + └── static + └── css + └── style.css +``` +This is where most of the magic happens: +- The default.md file in the archetypes directory dictates what template to follow when adding new post files. +- The layouts directory is where most of the meat is: + - Firstly, there's the partials directory which contains outlines for sections which you want to be used multiple times across the site such as a footer (footer.html) + - Sceondly, we have _default which contains outlines for the two types of hugo pages; singles (single.html) such as this individual post page, and lists (list.html) such as the tags and posts pages on this site. + - Partials also contains index.html which (you guessed it!) is your home page. +- Last but not least, there's static which as you can see just has the css for the site (this is all looks though - the action happens in partials). + +Now the theme is sorted the next three things you need to know anything about (imho) are the content, public, and static directories: +- Content is where you put your posts - these are just markdown files which hugo converts to html for you. +- Public is where hugo puts your built - ready to be served - site. You can then copy this directory to wherever your webserver is looking eg. /var/www/jdysmcl +- Static is where assets which you want to use with your site are kept. I basically just use it for images which I can then reference from my posts. + +Now we've got the directory what's happening where admin out the way let's have a look at what some of the html files in the themes directory look like; this is the index.html for my site for example: +```html +{{ partial "header.html" . }} + +

This is mainly a place for me to document various +bits and bobs I've been doing on my computers. +I am a noob in most things so take anything written +here with a pinch of salt. Lots of love :)

+ +{{ .Content }} +{{ range .Site.RegularPages | first 5 }} +

{{ .Title }}

+ {{ .Summary }} +

+ {{ .Date.Format "06 Jan, 2006" }} | + {{ .WordCount }} words | + {{ .ReadingTime }} mins | + + {{ range (.GetTerms "tags") }} + {{ .LinkTitle }} + {{ end }} + +{{ end }} + +{{ partial "footer.html" . }} +``` +In short, this plops the header and footer partials at the top and bottom of the page respectively, includes a short warning not to listen to me, and then displays my five most recent posts along with a snippet of the post and some accompanyning info: date, word count, reading time, and tags. The keen eyed among you will have noticed that this is a mish mash of normal html tags and strange stuff enclosed in double curly brackets. I'm going to end on this cliffhanger but if you want to know more about the curly brackets check out the hugo docs [here](https://gohugo.io/templates/introduction). diff --git a/content/posts/simple-nixos-config-for-static-site-on-vps.md b/content/posts/simple-nixos-config-for-static-site-on-vps.md new file mode 100644 index 0000000..ec97579 --- /dev/null +++ b/content/posts/simple-nixos-config-for-static-site-on-vps.md @@ -0,0 +1,85 @@ +--- +title: simple nixos config for vps static site +date: 2023-01-29 +tags: + - nixos +draft: false +--- + +Setting up a little static site is something I've done a few different times on a few different operating systems. It's a slightly fiddly task with a few disparate jobs that all need looking after: ssh, let's encrypt, nginx. In my opinion, it is one of the moments where consolidating all the little bits and bobs you need to setup into one common configuration is very useful. + +I'm going to go through a bit of the nixos config I've got for my vps. + +### SSH + +Having a way to to get into your server is useful. Managing ssh on nix is very simple; this enables the ssh daemon, tells it what port to run on, disables plain text passwords, and disables root login. + +```nix +services.openssh = { + enable = true; + ports = [ 69 ]; + settings = { + passwordAuthentication = false; + permitRootLogin = "no"; + }; +}; +``` + +### ADDING A USER + +Generally, it's nice to have a user so you're not just rawdogging everything as root. This adds a user called ronald, sets their default shell, and adds them to some useful groups. You can even add your public ssh keys here for ultimate convenience. + +```nix +users.users = { + ronald = { + isNormalUser = true; + shell = pkgs.fish; + extraGroups = [ "wheel" "nginx" ]; + openssh.authorizedKeys.keyFiles = [ "/path/to/public/key/file" ] + }; +}; +``` + +### NGINX + +I use nginx to serve my sites. Compared to the nginx config I used to mess around with, the equivalent nix config is very clean. This chunk tells nginx to serve the contents of `/var/www/example-site` at `example-site.here`. It also opens the ports for http and https in the firewall. + +```nix +services.nginx = { + enable = true; + virtualHosts."example-site.here" = { + enableACME = true; + forceSSL = true; + root = "/var/www/example-site/"; + }; +}; +networking.firewall.allowedTCPPorts = [ 80 443 ]; +``` + +### HTTPS + +You can also make nix deal with all the let's encrypt certbot stuff. It looks like this: + +```nix +security.acme = { + acceptTerms = true; + defaults.email = "ronald@email.yes"; +}; +``` + +This will set up certificates for any sites you set the `enableAMCE` to true option for. + +### CRON + +This is one final little tidbit I set up the other day. I had got bored of having to ssh into my server to manually copy my updated site to the website root. The problem was I would need root privileges on the server to rsync the files to the website root. This seemed like a whole minefield I didn't want to mess with. Instead I set up a little cron job which copies a directory from my home to the website root every hour. + +```nix +services.cron = { + enable = true; + systemCronJobs = [ + "@hourly root cp -r /home/ronald/example-site /var/www/" + ]; +}; +``` + +This means I can just rsync the updated site from my laptop to the server and it'll be updated within the hour. Good enough for me. diff --git a/content/posts/ssl-reverse-proxy-for-services-running-on-tailscale.md b/content/posts/ssl-reverse-proxy-for-services-running-on-tailscale.md new file mode 100644 index 0000000..231a748 --- /dev/null +++ b/content/posts/ssl-reverse-proxy-for-services-running-on-tailscale.md @@ -0,0 +1,36 @@ +--- +title: nginx reverse-proxy with SSL for services running on tailscale! +date: 2023-09-12 +tags: + - tailscale + - nixos +draft: true +--- + +So you're running something on a server somewhere. For whatever reason you cant or don't want to expose ports 80 and 443 to the outside world. + +```nix +services.jellyfin.enable = true; + +security.acme = { + acceptTerms = true; + defaults = { + email = "barry@email.com"; + dnsProvider = "cloudflare"; + credentialsFile = "/etc/credentials.env"; + }; +}; + +services.nginx = { + enable = true; + virtualHosts."example.com" = { + enableACME = true; + acmeRoot = null; + addSSL = true; + locations."/" = { + proxyPass = "http://127.0.0.1:8096"; + proxyWebsockets = true; + }; + }; +}; +``` diff --git a/content/posts/tailscale-caddy-nixos-containers.md b/content/posts/tailscale-caddy-nixos-containers.md new file mode 100644 index 0000000..57dadbd --- /dev/null +++ b/content/posts/tailscale-caddy-nixos-containers.md @@ -0,0 +1,77 @@ +--- +title: tailscale, caddy, and nixos containers - a match made in heaven +date: 2023-05-16 +tags: + - nixos + - caddy + - tailscale + - self-hosting +draft: false +--- +For a little while now I've been running some services (jellyfin etc.) on an old laptop in my house. I'm not trying to sound like a podcast ad but as a networking novice, the simplicity [tailscale](https://tailscale.com/) brings to accessing these services remotely is very nice. Until recently though, I had been accessing my services like a heathen with http and port numbers (eg http://tailscale-ip:service-port). This works and is perfectly secure thanks to tailscale though it lacks a certain finesse. In an ideal world you'd have a reverse proxy and set up SSL certs so your browser doesn't get stressed and you dont have to rememeber ip addresses and port numbers. + +When I initially looked at how to do this it seemed like it was above my paygrade and not worth the stress; that was until I came across [this](https://caddy.community/t/https-in-your-vpn-caddy-now-uses-tls-certificates-from-tailscale/15380). This works great and is as simple as advertised though there is one drawback: you can only reverse proxy one service per host. So for my usecase of the laptop with multiple services running on it I could only use the magic caddy tailscale auto-https thing for one of them. + +### what to do? + +Seeing as I was already using nixos on my latop server I turned to a slightly cumbersome nixos solution. One [nixos-container](https://nixos.wiki/wiki/NixOS_Containers) for each service I wanted over https. I'd be lying If I said I completely understand all of this NAT business but this was the config I cobbled together (copied from the nixos docs). + +```nix + networking.nat = { + enable = true; + internalInterfaces = ["ve-+"]; + externalInterface = "ens3"; + }; + + containers.jellyfin = { + autoStart = true; + enableTun = true; + privateNetwork = true; + hostAddress = "192.168.100.10"; + localAddress = "192.168.100.11"; + bindMounts = { + "/films" = { + hostPath = "/mnt/films"; + }; + }; + + config = { pkgs, ... }: { + + services.tailscale = { + enable = true; + # permit caddy to get certs from tailscale + permitCertUid = "caddy"; + }; + + services.jellyfin = { + enable = true; + openFirewall = true; + }; + + services.caddy = { + enable = true; + extraConfig = '' + + jellyfin.tailnet-name.ts.net { + reverse_proxy localhost:8096 + } + + ''; + }; + + + # open https port + networking.firewall.allowedTCPPorts = [ 443 ]; + + system.stateVersion = "23.05"; + + }; + }; +} +``` + +This example enables the jellyfin, tailscale, and caddy services, mounts a film folder from the host, and lets the container talk to the internet. + +Once you've logged into the container `sudo nixos-container root-login jellyfin` and authenticated with tailscale `sudo tailscale up`, you should be able to access your jellyfin in your browser at `https://jellyfin.tailnet-name.ts.net`. + +As well as solving the multiple services problem, separating services onto their own hosts is nice if you want to [share](https://tailscale.com/kb/1084/sharing/) a particular service with someone else. I personaly feel happier just sharing one container running jellyfin rather than the whole host with multiple things on it. Anyway thanks for listening to my TED talk. diff --git a/content/posts/teeny-tiny-bash-fetch-script.md b/content/posts/teeny-tiny-bash-fetch-script.md new file mode 100644 index 0000000..4b5c6bb --- /dev/null +++ b/content/posts/teeny-tiny-bash-fetch-script.md @@ -0,0 +1,95 @@ +--- +title: teeny tiny bash fetch script +date: 2022-12-10 +tags: + - bash +draft: false +--- + + +This is my attempt at a neofetch, pfetch, whateverfetch style system info utility. My main concern was making something which looked nice, was easily configurable, and as portable as possible (I didn't really try that hard with the portability). I didn't think much about performance; I'm personally not a man who stresses too much when a command takes a quarter of a second instead of a tenth. The basic gameplan was to get an array of bash commands which would fetch various bits and bobs, then loop through this array formatting the text with ANSI escape codes. First things first, this was the associative array I came up with: + +```bash +declare -A fetch=( + [user]="$USER" + [host]="$(cat /etc/hostname)" + [uptime]="$(uptime | awk '{print $3}' | sed 's/:/h / ; s/,/m/')" + [kernel]="$(awk '{print $3}' /proc/version)" + [distro]="$(sed -n 's/^PRETTY_NAME="//p' /etc/os-release | sed 's/"//')" + [shell]="$(basename $SHELL)" + [de]="$XDG_CURRENT_DESKTOP" + [terminal]="$TERM" + [editor]="$EDITOR" + [root]="$(df -Th / | tail -n 1 | awk '{print $6}'), + $(df -Th / | tail -n 1 | awk '{print $2}')" + [ip]="$(host myip.opendns.com resolver1.opendns.com | + tail -n 1 | awk '{print $4}')" + [battery]="$(cat /sys/class/power_supply/BAT0/capacity)%" + [cpu]="$(sed -n 5p /proc/cpuinfo | cut -d: -f2)" + [ram]="$(free -h | sed -n 2p | awk '{print $3}') / + $(free -h | sed -n 2p | awk '{print $2}')" + [swap]="$(free -h | sed -n 3p | awk '{print $3}') / + $(free -h | sed -n 3p | awk '{print $2}')" + [display]="$(xrandr | grep '*' | awk '{print $1}'), + $(xrandr | grep '*' | awk '{print $2}' | sed 's/*/Hz/ ; s/+//')" +) +``` + +Each of these elements fetches a differenet piece of info. You could just use environment variables to get quite a few things (user), some were an issue of grabbing a particular piece of info from a file (distro name), and some of the more complicated ones I just reformatted output from other commands (ram usage). + +Next order of business: colors. I wanted to put a chunk or randomly colored text at the start of each line so that each time you ran the command you got something that looked a little different. I made this array of escape codes each one referring to a different bold color: + +```bash +declare -a colors=( + "\e[0;1;30m" # black + "\e[0;1;31m" # red + "\e[0;1;32m" # green + "\e[0;1;33m" # blue + "\e[0;1;34m" # yellow + "\e[0;1;35m" # pink + "\e[0;1;36m" # magenta + "\e[0;1;37m" # white +) +``` + +I then repurposed a nice function from someone on stackoverflow to get a random element from this array. The variable 'pre' here is the text that I want formatted: + +```bash +pre="->" + +random_color () { + size=${#colors[@]} + index=$(($RANDOM % $size)) + echo "${colors[$index]}${pre}\e[0m" +} +``` + +My plan was then to simply loop through the array, 'echo-ing' out the random_color function, the key from the fetch array, a separator, and then the value form the fetch array. This worked mainly, the only issue being that each element from the fetch was not printed in the order it was declared. Ideally, I wanted the fetch elements to be printed in the order they were put in the array so you could configure the how they appeared. Once again my primitive understanding of bash had let me down; I turned to stackoverflow. I found the solution was to define another array containing the fetch keys and then use it to attack the other associative 'fetch' array: + +```bash +declare -a order=( + "user" + "host" + "uptime" # uses uptime command + "kernel" + "distro" + "shell" + "de" + "terminal" + "editor" + # "ip" # uses host command + # "cpu" + # "ram" # uses free command + # "swap" # uses free also + # "root" # uses df command + # "battery" + # "display" # uses xrandr +) + +for info in "${order[@]}"; do + echo -e "$(random_color) \e[0;1;3m$info\e[0m${sep}${fetch[$info]}" +done +``` + This had the happy unintended consequence of allowing you to very easily configure which items you wanted in the fetch by simply commenting out keys from the order array. You can check out the script in its entirety [here](https://gitlab.com/robbygozzarder/golazo). This is a pretty picture of a few variations. + +![golazo](/image/golazo.png) diff --git a/content/posts/upgrade-your-qtile-setup-with-a-cute-dropdown-terminal.md b/content/posts/upgrade-your-qtile-setup-with-a-cute-dropdown-terminal.md new file mode 100644 index 0000000..619d04d --- /dev/null +++ b/content/posts/upgrade-your-qtile-setup-with-a-cute-dropdown-terminal.md @@ -0,0 +1,71 @@ +--- +title: upgrade your qtile setup with a cute dropdown terminal +date: 2022-09-23 +tags: + - python + - qtile +draft: false +--- + + +I didn't know you could do this until recently, very fun and playful little feature. How you want to do it will depend slightly on how you have your groups set up but I start with importing the relevant libraries and defining an empty list. + +```python +from libqtile.config import Dropdown, Scratchpad + +groups = [] +``` + +I'm then able to append all the groups I want to this list. For the dropdown terminal you need the ScratchPad group which to quote the [qtile docs](https://docs.qtile.org/en/latest/manual/config/groups.html) is a "special - by default invisible - group which acts as a container for DropDown configurations". My configuration looks like this: + +```python +groups.append( + ScratchPad( "scratchpad", [ + DropDown( + "term", + kitty, + opacity = 0.9, + ), + ] + ), +) +``` + +This gives you a terminal (kitty in this case) with a little tranparency. By default, it will pop up with this size: + +![alt](/image/dropdown.webp) + +Though this can easily be altered with the x, y, height, and width keys: + +```python +groups.append( + ScratchPad("scratchpad", [ + DropDown( + "term", + kitty, + opacity = 0.9, + x = 0, + y = 0, + width = 0.3, + height = 0.5, + ), + ]) +) +``` + +This gives us a little boxy guy in the top left corner: + +![alt](/image/dropdown2.webp) + +We also have the option to set keybindings to toggle the appearance of the window. I've got this in my config.py now: + +```python +keys = [ + Key([m, "shift"], "Return", + lazy.group["scratchpad"].dropdown_toggle("terminal"), + desc='dropdown term' + ), +] +``` + +Anyway, hope this was useful, happy configurating :) diff --git a/content/posts/vanilla-javascript-theme-toggle-for-simpletons.md b/content/posts/vanilla-javascript-theme-toggle-for-simpletons.md new file mode 100644 index 0000000..694ce24 --- /dev/null +++ b/content/posts/vanilla-javascript-theme-toggle-for-simpletons.md @@ -0,0 +1,120 @@ +--- +title: vanilla javascript theme toggle for simpletons +date: 2023-06-26 +tags: + - javascript + - css +draft: false +--- + +Sometimes when I'm trawling the internet and happen upon a particularly nice looking website, I develop css and javascript FOMO. The thing I've been lusting after above all else is one of those fancy little dark theme toggle buttons. As you can probably tell from the website you're looking at my web dev skills are limited. As a result of this I had assumed such niceties were out of reach. + +Last week though I decided it was time for this to change! I would do a teeny bit of javascript. I could have nice things. This is a rundown of the very simple implementation I came up with. + +### HTML + +First things first, we'll need a button for users to click. This can be plopped wherever you want on your site. + +```html +