Skip to content

Instantly share code, notes, and snippets.

🔛

James J Porter porterjamesj

🔛
Block or report user

Report or block porterjamesj

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@amorgun
amorgun / sample.py
Created Nov 10, 2017
SqlAlchemy postgres bulk upsert
View sample.py
from sqlalchemy.dialects import postgresql
def bulk_upsert(session: Session,
items: Sequence[Mapping[str, Any]]):
session.execute(
postgresql.insert(MyModel.__table__)
.values(items)
.on_conflict_do_update(
index_elements=[MyModel.id],
set_={MyModel.my_field.name: 'new_value'},
@pv8
pv8 / fix-venv.sh
Last active Dec 11, 2019
Fix virtualenv symlinks after upgrading python with Homebrew and running brew cleanup
View fix-venv.sh
#!/usr/bin/env bash
#
# Fix virtualenv symlinks after upgrading python with Homebrew and then running
# `cleanup`.
#
# After upgrading Python using Homebrew and then running `brew cleanup` one can
# get this message while trying to run python:
# dyld: Library not loaded: @executable_path/../.Python
# Referenced from: /Users/pablo/.venv/my-app/bin/python
# Reason: image not found
@ArthurYidi
ArthurYidi / translatekeycodes.swift
Created Apr 6, 2016
virtual key codes to unicode characters
View translatekeycodes.swift
func keyCodeToString(keyCode: CGKeyCode) -> String {
let curKeyboard = TISCopyCurrentKeyboardInputSource().takeRetainedValue()
let ptr = TISGetInputSourceProperty(curKeyboard, kTISPropertyUnicodeKeyLayoutData)
let keyboardLayoutPtr = UnsafePointer<UCKeyboardLayout>(ptr)
var deadKeyState: UInt32 = 0
var actualStringLength = 0
var unicodeString = [UniChar](count: 255, repeatedValue: 0)
let status = UCKeyTranslate(keyboardLayoutPtr,
@bruienne
bruienne / xhyverun.sh
Last active Oct 4, 2018
xhyve boot2docker sample config
View xhyverun.sh
#!/bin/sh
KERNEL="/path/to/vmlinuz64"
INITRD="/path/to/initrd.img"
#CMDLINE="earlyprintk=serial console=ttyS0 acpi=off"
CMDLINE="loglevel=3 user=docker console=ttyS0 console=tty0 noembed nomodeset norestore waitusb=10:LABEL=boot2docker-data base"
MEM="-m 1G"
#SMP="-c 2"
NET="-s 2:0,virtio-net,en0"
@madrobby
madrobby / gist:c55f39bfdbd60bf14671
Last active Aug 23, 2018
Deny commonly used security-probing things that spam up log files (for a Rails app)
View gist:c55f39bfdbd60bf14671
location ~ ^/(wp-admin|wp-login\.php|priv\.dog|companies\/sidekick) {
deny all;
break;
}
# file extensions that should never be served, this prevents
# potential malicious downloads in case someone manages to manipulate
# a Rails URL or write a file that can be served
# (~* matches case-insensitive)
location ~* \.(?:git|svn|DS_Store|asp|aspx|cgi|pt|pl|idx|php|exe|scpt|AppleScript|dll|dmg|pif|msi|application|msp|com|scr|hta|cpl|gadget|msc|jar|bat|vb|vbs|vbe|ws|wsh|inf|lnk|reg|scf|wsc|wsh|ps1|ps1xml|ps2|ps2xml|psc1|psc2|msh|msh1|msh2|mshxml|msh1xml|msh2xml)$ {
deny all;
View flycheck-julia.el
(flycheck-define-checker julia-lint
"A Julia syntax checker using Lint.jl."
:command ("julia" "-e"
"using Lint; lintfile(ARGS[1])" source-inplace)
:error-patterns
((info line-start
(zero-or-more blank)
(file-name) " "
(one-or-more (not digit))
line " INFO" (one-or-more blank) (message) line-end)
@ihnorton
ihnorton / _pleasedontdothis_.jl
Last active Aug 29, 2015
Curiosity and his cat
View _pleasedontdothis_.jl
mem_size = 64
mem_prot = 0x40 # PAGE_EXECUTE_READWRITE
mem_type = 0x00001000 # MEM_COMMIT
ex_mem = ccall(:VirtualAlloc,
Ptr{Uint8},
(Ptr{Void}, Csize_t, Uint64, Uint64),
C_NULL, mem_size, mem_type, mem_prot) # call VirtualAlloc and get executable page
exec_arr = pointer_to_array(ex_mem, (32,2)); # consider as an array so we can write to it
@bitemyapp
bitemyapp / gist:8739525
Last active Dec 3, 2019
Learning Haskell
View gist:8739525
@petehunt
petehunt / gist:8396968
Created Jan 13, 2014
Sweet.js DSL for making persistent data structures feel imperative
View gist:8396968
macro := {
rule infix { $obj $([ $key ] ...) | $rval:expr } => {
$obj = mori.assoc_in($obj, [$key (,) ...].reverse(), $rval)
}
}
macro hash_map {
rule {{ $($key : $value) (,) ... }} => {
mori.hash_map($($key, $value) (,) ...)
}
@johnmyleswhite
johnmyleswhite / type_inference.jl
Created Aug 9, 2013
Julia's type inference is where you get performance
View type_inference.jl
# Always ignore one run
x = 0
@elapsed for i in 1:100_000_000
x += 1
end # => 3.330939854
# Second time is more accurate
You can’t perform that action at this time.