Skip to content

Instantly share code, notes, and snippets.

View alexhrescale's full-sized avatar

alex huang alexhrescale

  • Rescale
View GitHub Profile
@alexhrescale
alexhrescale / skip_manage.py
Created August 15, 2016 05:13
how to set up your own script, bypassing the manage.py dance
from __future__ import unicode_literals
import os, sys, django
from theproject import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'theproject.settings')
django.setup()
# now import normally, e.g.
from django.core.management.base import BaseCommand
@alexhrescale
alexhrescale / my-temp-mode.el
Created January 31, 2017 21:21
create a new emacs minor mode with custom C-RET binding
(defun my-temp-func ()
(interactive)
(insert "tempura true"))
(define-minor-mode my-temp-mode
"throwaway minor mode for test"
:lighter " TEMP!"
:keymap (let ((map (make-sparse-keymap)))
(define-key map [(control return)] 'my-temp-func)
(define-key map (kbd "C-c f") 'my-temp-func)
@alexhrescale
alexhrescale / nix-no-root.sh
Last active November 20, 2017 05:57
Bootstrap nix-env for a non-root user; based on https://github.com/pjotrp/nix-no-root
#! /bin/bash
#
# This script creates a working nix in $HOME
# ref https://github.com/pjotrp/nix-no-root
if [ $# -ne 1 ]; then
echo NEED NIX ROOT
exit 1
fi
import winrm
from winrm.protocol import Protocol
HOSTNAME='ec2-aaa-bbb-ccc-ddd.compute-1.amazonaws.com'
ENDPOINT='http://%s:5985/wsman' % HOSTNAME
USERNAME='Administrator'
PASSWORD='blahblah'
p = Protocol(
endpoint=ENDPOINT,
@alexhrescale
alexhrescale / sqlstuff.cljs
Created January 22, 2018 02:26
sql generation for sequelize-loaded tables with some level of auto-join discovery
;; messy but potentially useful
;; UTIL
(defn wrap-quote [s]
(str "\"" s "\""))
(defn wrap-single-quote [s]
(str "'" s "'"))
@alexhrescale
alexhrescale / execute-with-marker.el
Created August 29, 2018 20:14
convenience emacs methods to execute in shell buffer and capture output into comments
(setq copy-output-marker " # <EOF__>")
(defun execute-with-marker ()
(interactive)
(kill-ring-save
(line-beginning-position)
(line-end-position))
(end-of-line)
(setq my-comint-originator-buffer (buffer-name))
(other-window 1)
@alexhrescale
alexhrescale / configuration.nix
Last active January 4, 2019 17:10
nixos vagrant sample config
# see https://github.com/nix-community/nixbox/blob/master/scripts/configuration.nix
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
./vagrant.nix
];
@alexhrescale
alexhrescale / default.nix
Last active January 16, 2019 19:24
quick tmux shell env
with import <nixpkgs> {};
stdenv.mkDerivation rec {
name = "dev-env";
env = pkgs.buildEnv {
name = name;
paths = buildInputs;
};
buildInputs = [
(vim_configurable.override {
@alexhrescale
alexhrescale / gist:258b7854a4f3e6e73cb372ad46d00d08
Created January 17, 2019 22:48
quick env with virtualenv + override .zshrc + zsh theme + vim_configurable PATH fix
let
pkgs = import <nixpkgs> {};
stdenv = pkgs.stdenv;
in stdenv.mkDerivation rec {
name = "quick";
env = pkgs.buildEnv { name = name; paths = buildInputs; };
buildInputs = [
pkgs.python27Packages.virtualenv
@alexhrescale
alexhrescale / dircontentinfo
Last active June 26, 2020 02:07
get directory content information
#!/bin/bash
if [ $# -lt 1 ]; then
cat <<EOF
Usage: $0 <directory> [tabwidth]
This script outputs a table of file information from the contents of <directory> like:
time type perm uid size mime hash path target
4444 file -rw- 0 1111 text/... abcd /x/f