Skip to content

Instantly share code, notes, and snippets.

View peter-kehl's full-sized avatar
🏠
Working from home

Peter Kehl peter-kehl

🏠
Working from home
View GitHub Profile

So I had this situation where I needed to delete an object from the database, if it existed. This is what I wrote:

Ruby Option 1

obj = get_object(1)
obj.destroy if obj

And as I wrote this, it seemed a bit awkward to me. We always said Ruby had a really elegant syntax, but I guess I've come to the place where I find it a little grating. The thing about this example is the asymmetry of it. Conceptually I feel like the if check goes with the assignment, but it's separated from it in a strange way.

Ruby Option 2

@okitavera
okitavera / userChrome.css
Created January 24, 2018 12:09
Custom userChrome.css for firefox 57 for auto-hiding the navigation bar and bookmark bar
/* Auto-hide toolbar */
:root[uidensity=compact] #navigator-toolbox {
--nav-bar-height: 33px;
}
:root:not([uidensity]) #navigator-toolbox {
--nav-bar-height: 39px;
}
:root[uidensity=touch] #navigator-toolbox {

Google Apps Script Gmail Utilities

##sendAndLabel(recipient, subject, body, options, label)##

An alternative to GmailApp.sendEmail(), which applies a label to the message thread in the sender's account.

Sends an email message with optional arguments. The email can contain plain text or an HTML body. The size of the email

(require '[clojure.core.async :as a])
(def xform (comp (map inc)
(filter even?)
(dedupe)
(flatmap range)
(partition-all 3)
(partition-by #(< (apply + %) 7))
(flatmap flatten)
(random-sample 1.0)
@hallettj
hallettj / userChrome.css
Last active June 23, 2023 18:05
Customize Firefox Quantum to hide tab bar, and to hide navigation bar when it is not focused. Press Ctrl+L to reveal navigation bar. To make this work you must open about:config and set toolkit.legacyUserProfileCustomizations.stylesheets to true with. This version is tested with Firefox v78.
@-moz-document url(chrome://browser/content/browser.xul),
url(chrome://browser/content/browser.xhtml) {
/* hide horizontal tabs at the top of the window */
#TabsToolbar > * {
visibility: collapse;
}
/* hide navigation bar when it is not focused; use Ctrl+L to get focus */
#main-window:not([customizing]) #navigator-toolbox:not(:focus-within):not(:hover) {
@levand
levand / cider-opinions.md
Last active November 20, 2023 07:50
Why I don't use cider

Why I don't use cider.

This is all personal opinion and a matter of taste. I'm putting it here because people have asked - I'm glad Cider exists and that a lot of people are obviously using it to great effect. This is not an attack on Cider or a an attempt to negate the experience of those who like it, just my own experience.

Also some of the critiques are more properly aimed at nRepl than Cider - I don't use nRepl either, in Emacs. For some reason I have fewer issues with it in Cursive (though I still do have some).

  1. With Cider, there's too much "going on" between Emacs and Clojure. When something glitches, hangs, doesn't return a value, throws an excption, etc (as it does, multiple times a day), I don't know whether the problem is in Emacs, in the Cider client, the nRepl server, one of any of the default middlewares or in my actual program. I run Emacs in inferior lisp using lein trampoline -m clojure.main - if something goes wrong, it's either in Emacs (which is usually obvious) or my program. Mi
@getify
getify / ex1-prototype-style.js
Last active January 7, 2024 11:58
OLOO (objects linked to other objects) pattern explored (with comparison to the prototype style of the same code)
function Foo(who) {
this.me = who;
}
Foo.prototype.identify = function() {
return "I am " + this.me;
};
function Bar(who) {
Foo.call(this,"Bar:" + who);
@peterhs73
peterhs73 / virtualenv_n_jupyter_kernel.md
Last active February 23, 2024 17:37
Python Virtual Environments and Jupyter Notebook Kernel Guide

Create Python Virtual Environment and Install iPython Kernel for researchers working with Jupyter notebooks.

TL;DR

  • Virtual Environment
    • Virtualenv
      virtualenv env_to_create  
      \folder_to_create\Scripts\activate
      
@peter-kehl
peter-kehl / rust_const_generics.md
Last active March 28, 2024 15:07
Rust Const Generics

Presentation on Const Generics as of 1.50.0 stable and 1.52.0-nightly

Challenges

  • Beware no, or misleading, documentation
  • Syntax may seem arbitrary:
    • Need ::< turbofish at some places, ordinary < elsewhere.
    • Need {...} curly brackets around some const generic parameter values, not around others.
    • Some error messages feel like going in circles.
@Noitidart
Noitidart / _git-submodule-tips.md
Last active March 29, 2024 22:43
Tips for working with git submodules

Tips for Working With git Submodules

Cloning Repo with Submodules

  1. Use the --recursive flag:

     git clone https://github.com/aikiframework/json.git --recursive
    

    However if you cannot, as Github desktop app on clone does not use this flag, then do this after clone: