Skip to content

Instantly share code, notes, and snippets.

@nxtr
nxtr / Charset.cls
Created March 20, 2017 14:08
Salesforce Force.com Apex: encode and decode string to / from binary characters in charset
public abstract class Charset {
/**
* Convenience method that encodes a string into bytes in charset.
* <p>
* @param input string of Unicode characters
* @param charset name according to http://www.iana.org/assignments/character-sets/character-sets.xhtml
* @return binary characters in charset
*/
public static Blob encode(final String input, final String charset) {
@nxtr
nxtr / tooling-v41.0.wsdl
Created January 6, 2018 01:04
Salesforce.com Tooling API version 41.0 with no xsd:element type attr (search for fns:type) instead of type="fns:LoginFault" etc.
<?xml version="1.0" encoding="UTF-8"?>
<!--
Salesforce.com Tooling API version 41.0
Copyright 2006-2017 Salesforce.com, inc. All Rights Reserved
-->
<definitions targetNamespace="urn:tooling.soap.sforce.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="urn:tooling.soap.sforce.com" xmlns:mns="urn:metadata.tooling.soap.sforce.com" xmlns:ens="urn:sobject.tooling.soap.sforce.com" xmlns:fns="urn:fault.tooling.soap.sforce.com">
<types>
<xsd:schema elementFormDefault="qualified" targetNamespace="urn:metadata.tooling.soap.sforce.com">
<xsd:import namespace="urn:sobject.tooling.soap.sforce.com"/>
@nxtr
nxtr / subr.el
Created August 16, 2018 15:02
with-file-temp-buffer: (FILENAME &rest BODY)
(defmacro with-file-temp-buffer (filename &rest body)
"Create a temporary buffer visiting FILENAME, and evaluate BODY there like
`progn'."
(declare (indent 1) (debug t))
(let* ((temp-buffer (make-symbol "temp-buffer")))
`(let* ((truename (abbreviate-file-name (file-truename ,filename)))
(number (nthcdr 10 (file-attributes truename)))
(,temp-buffer (find-file-noselect-1
(create-file-buffer ,filename)
,filename 'nowarn nil truename number)))
@nxtr
nxtr / key-bindings.el
Created August 20, 2018 15:51
Key binding of a lambda function as a uninterned symbol,
(define-key ivy-mode-map (kbd "C-s")
(defalias (make-symbol "swiper-or-swiper-all")
;; Wrapped in `defalias' with uninterned SYMBOL so `describe-key'
;; displays command as a proper symbol instead of byte-codes
(lambda ()
"Runs the command swiper.
With a prefix argument, run the command swiper-all."
(interactive)
(if current-prefix-arg
(swiper-all)
@nxtr
nxtr / ert.el
Created August 25, 2018 09:42
EVM_EMACS=emacs-24.3-travis,Test all-completions condition: (invalid-function (a b)), Test all-completions backtrace: (a b)("" nil t) all-completions("" (a b) nil)
(ert-deftest all-completions ()
(should
(equal '("a" "b") (all-completions "" '(a b) nil))))
@nxtr
nxtr / files.el
Created September 3, 2018 18:28
Convert filename NAME to absolute and canonicalize, starting with directory of `load-file-name' or `buffer-file-name' or `default-directory' if NAME is relative (does not start with slash or tilde).
(defun expand-file-name-current-directory (name)
"Convert filename NAME to absolute and canonicalize, starting with directory
of `load-file-name' or `buffer-file-name' or `default-directory' if NAME
is relative (does not start with slash or tilde)."
(let ((dir (file-name-directory (or load-file-name buffer-file-name ""))))
(expand-file-name name dir)))))
@nxtr
nxtr / expand-file-name-current-directory.el
Created December 9, 2018 23:51
Convert filename NAME to absolute and canonicalize, starting with directory of `load-file-name' or `buffer-file-name' or `default-directory' if NAME is relative (does not startwith slash or tilde).
(eval-and-compile
(unless (fboundp 'expand-file-name-current-directory)
(defun expand-file-name-current-directory (name)
"Convert filename NAME to absolute and canonicalize.
Starting with directory of `load-file-name' or `buffer-file-name' or
`default-directory' if NAME is relative (does not startwith slash or tilde)."
(let ((dir (file-name-directory (or load-file-name buffer-file-name ""))))
(expand-file-name name dir)))))
@nxtr
nxtr / ivy-posframe-get-size.el
Last active January 29, 2021 18:19
A dynamic and adaptive function used by `ivy-posframe-size-function'
(ivy-posframe-size-function
(lambda ()
(list
:height (or ivy-posframe-height ivy-height)
:width ivy-posframe-width
:min-height (or ivy-posframe-min-height ivy-height)
:min-width (or ivy-posframe-min-width
(let* ((buf-rows (split-string
(with-current-buffer ivy-posframe-buffer
(buffer-string))
@nxtr
nxtr / nxtr-ivy-posframe--display.el
Last active January 29, 2021 08:53
ivy-posframe: Advice for default font from selected frame
(define-advice ivy-posframe--display (:around (fun &rest args))
(let ((ivy-posframe-font (face-attribute 'default :font (selected-frame))))
(apply fun args)))
@nxtr
nxtr / .sommelierrc
Created January 10, 2021 12:56
Chrome OS, Crostini, Sommelier: Import environment from ~/.bash_profile and ~/.profile
# Copyright 2020 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Use this file to customize per-user sommelier options.
#
# For documentation, see:
# https://chromium.googlesource.com/chromiumos/platform2/+/HEAD/vm_tools/sommelier/
# Import environment from ~/.bash_profile and ~/.profile