Skip to content

Instantly share code, notes, and snippets.

View messense's full-sized avatar
🐢
I may be slow to respond on workdays.

messense messense

🐢
I may be slow to respond on workdays.
View GitHub Profile
@rbtcollins
rbtcollins / demo.py
Last active February 8, 2018 02:42
Getting at the mystery object
from ctypes import *
pythonapi.PyDict_SetItemString.argtypes=[c_void_p, c_char_p, c_void_p]
class PyObject(Structure):
_fields_ = [("refcnt", c_size_t),
("typeid", c_void_p)]
pythonapi.PyThreadState_GetDict.restype = POINTER(PyObject)
pythonapi.PyDict_SetItemString(c_void_p(id(locals())), b"threaddict", pythonapi.PyThreadState_GetDict())
repr([1])
print(threaddict)
#![feature(unicode, core_intrinsics)]
struct MyString(String);
impl From<Vec<char>> for MyString {
fn from(mut chars: Vec<char>) -> MyString {
let mut bytes_used = 0usize;
let length = chars.len();
for index in 0..length {
let current_char = unsafe { *chars.get_unchecked(index) };
let output_buf: &mut [u8] = unsafe {
"""
Map oplog to you custom interface. To, for example, have triggers in mongo.
see example in '__main__' below
https://gist.github.com/rescommunes/4e5035242b8e4b07ff3a
"""
import logging
from time import sleep
import pickle
@steve-jansen
steve-jansen / README.md
Last active May 21, 2024 04:59
Stop and start Symantec Endpoint Protection on OS X

This script enables you stop and start Symantec Endpoint Protection on OS X

Installation

sudo curl https://gist.githubusercontent.com/steve-jansen/61a189b6ab961a517f68/raw/sep -o /usr/local/bin/sep
sudo chmod 755 /usr/local/bin/sep
sudo chown root:staff /usr/local/bin/sep
@LeCoupa
LeCoupa / bash-cheatsheet.sh
Last active May 22, 2024 09:39
Bash CheatSheet for UNIX Systems --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
#!/bin/bash
#####################################################
# Name: Bash CheatSheet for Mac OSX
#
# A little overlook of the Bash basics
#
# Usage:
#
# Author: J. Le Coupanec
# Date: 2014/11/04
@mlynch
mlynch / auth.markdown
Last active September 4, 2020 18:11
AngularJS Authentication and CORS

Single Page Apps are ruling the world and AngularJS is leading the charge. But many of the lessons we learned in the Web 2.0 era no longer apply, and few are as drastically different as authentication.

CORS

CORS is an oft-misunderstood feature of new browsers that is configured by a remote server. CORS stands for Cross-Origin-Resource-Sharing, and was designed to make it possible to access services outside of the current origin (or domain) of the current page.

Like many browser features, CORS works because we all agree that it works. So all major browsers like Chrome, Firefox, and IE support and enforce it. By using these browsers, you benefit from the security of CORS.

That means certain browsers do not enforce it, so it is not relevant there. One large example is a native Web View for things like Cordova and Phonegap. However, these tools often have configuration options for whitelisting domains so you can add some security that way.

@atheriel
atheriel / macroexpand.c
Last active January 20, 2018 07:58
Can one write a Python extension in Rust?
PyObject * RustPy_InitModule(const char *name, PyMethodDef *methods, const char *doc) {
// return Py_InitModule4(name, methods, doc, (PyObject *) NULL, PYTHON_API_VERSION);
return Py_InitModule3(name, methods, doc);
}
@carljm
carljm / db.py
Last active May 1, 2023 00:54
SQLAlchemy and Postgres autocommit
"""
SQLAlchemy, PostgreSQL (psycopg2), and autocommit
See blog post: http://oddbird.net/2014/06/14/sqlalchemy-postgres-autocommit/
"""
from contextlib import contextmanager
from sqlalchemy import create_engine, event
from sqlalchemy.orm import sessionmaker, Session as BaseSession
@hest
hest / gist:8798884
Created February 4, 2014 06:08
Fast SQLAlchemy counting (avoid query.count() subquery)
def get_count(q):
count_q = q.statement.with_only_columns([func.count()]).order_by(None)
count = q.session.execute(count_q).scalar()
return count
q = session.query(TestModel).filter(...).order_by(...)
# Slow: SELECT COUNT(*) FROM (SELECT ... FROM TestModel WHERE ...) ...
print q.count()
@plentz
plentz / nginx.conf
Last active May 17, 2024 09:08
Best nginx configuration for improved security(and performance)
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048