Skip to content

Instantly share code, notes, and snippets.

import JavaScript from 'tree-sitter-javascript';
import TypeScript from 'tree-sitter-typescript';
import Python from 'tree-sitter-python';
import Go from 'tree-sitter-go';
import Swift from 'tree-sitter-swift';
import Java from 'tree-sitter-java';
import Kotlin from 'tree-sitter-kotlin';
import C from 'tree-sitter-c';
import CPlusPlus from 'tree-sitter-cpp';
import Rust from 'tree-sitter-rust';
@ghughes
ghughes / __init__.py
Created June 28, 2023 02:21
UniXcoder in Python
import torch
from torch.nn.functional import normalize
from .unixcoder import UniXcoder
class UniXcoderEmbeddings:
def __init__(self, model_name="microsoft/unixcoder-base"):
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
self.model = UniXcoder(model_name).to(self.device)
def get_embedding(self, text):
@ghughes
ghughes / Dockerfile
Created February 8, 2022 20:15
Dockerfile to build a custom Pushpin image from Condure source. Cross-compiles for amd64 if built on an arm64 system.
FROM ubuntu:focal AS build
USER root
RUN apt-get update && apt-get install -y build-essential g++-multilib-x86-64-linux-gnu curl
RUN curl -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN rustup target add x86_64-unknown-linux-gnu
RUN curl http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl-dev_1.1.1f-1ubuntu2.8_amd64.deb -O \
&& curl http://security.debian.org/debian-security/pool/updates/main/z/zeromq3/libzmq3-dev_4.2.1-4+deb9u4_amd64.deb -O \
@ghughes
ghughes / locca.pde
Created November 27, 2011 19:33
Arduino sketch to activate Locca Remote Key via serial
const int basePin = 2;
void triggerRemote() {
digitalWrite(basePin, HIGH);
delay(2000);
digitalWrite(basePin, LOW);
}
void setup() {
pinMode(basePin, OUTPUT);
@ghughes
ghughes / middleware.py
Created November 15, 2011 17:11
DeleteSessionOnLogoutMiddleware
from django.conf import settings
"""Delete sessionid and csrftoken cookies on logout, for better compatibility with upstream caches."""
class DeleteSessionOnLogoutMiddleware(object):
def process_response(self, request, response):
if getattr(request, '_delete_session', False):
response.delete_cookie(settings.CSRF_COOKIE_NAME, domain=settings.CSRF_COOKIE_DOMAIN)
response.delete_cookie(settings.SESSION_COOKIE_NAME, settings.SESSION_COOKIE_PATH, settings.SESSION_COOKIE_DOMAIN)
return response
@ghughes
ghughes / django.vcl
Created November 15, 2011 16:05
Django VCL for Varnish
sub vcl_recv {
# unless sessionid/csrftoken is in the request, don't pass ANY cookies (referral_source, utm, etc)
if (req.request == "GET" && (req.url ~ "^/static" || (req.http.cookie !~ "sessionid" && req.http.cookie !~ "csrftoken"))) {
remove req.http.Cookie;
}
# normalize accept-encoding to account for different browsers
# see: https://www.varnish-cache.org/trac/wiki/VCLExampleNormalizeAcceptEncoding
if (req.http.Accept-Encoding) {
if (req.http.Accept-Encoding ~ "gzip") {