Skip to content

Instantly share code, notes, and snippets.

View FSX's full-sized avatar
💭
I may be slow to respond.

Frank FSX

💭
I may be slow to respond.
View GitHub Profile
@jeanbza
jeanbza / automate_2048.md
Last active July 9, 2023 03:42
Automate 2048

So I got to playing 2048 a decent amount, and starting getting the feeling that there was a 'pattern' that would win this game for me. Perhaps you've had the same thought! As a result, I wrote a little snippet of code that that cycles throw the keys Up, Right, Down, Left (feel free to create your own pattern).

Copy and paste this into your Chrome/Firefox console to automate 2048!

Firefox

function pressKey(i) {
  var evt = document.createEvent("KeyboardEvent");
  evt.initKeyEvent ("keydown", true, true, window, 0, 0, 0, 0, 37+i%4, 37+i%4);
 document.dispatchEvent(evt);
"""
This file contains code that, when run on Python 2.7.5 or earlier, creates
a string that should not exist: u'\Udeadbeef'. That's a single "character"
that's illegal in Python because it's outside the valid Unicode range.
It then uses it to crash various things in the Python standard library and
corrupt a database.
On Python 3... well, this file is full of syntax errors on Python 3. But
if you were to change the print statements and byte literals and stuff:
@datagrok
datagrok / gist:2199506
Last active April 8, 2023 17:36
Virtualenv's `bin/activate` is Doing It Wrong
from ijson import common
from ijson.backends import YAJLImportError
from cffi import FFI
ffi = FFI()
ffi.cdef("""
typedef void * (*yajl_malloc_func)(void *ctx, size_t sz);
typedef void (*yajl_free_func)(void *ctx, void * ptr);
typedef void * (*yajl_realloc_func)(void *ctx, void * ptr, size_t sz);
from sre_parse import Pattern, SubPattern, parse as sre_parse
from sre_compile import compile as sre_compile
from sre_constants import BRANCH, SUBPATTERN
class Scanner(object):
def __init__(self, tokens, flags=0):
subpatterns = []
pat = Pattern()
@parente
parente / runinenv.sh
Created February 15, 2011 01:54
run a command in virtualenv, useful for supervisord
#!/bin/bash
VENV=$1
if [ -z $VENV ]; then
echo "usage: runinenv [virtualenv_path] CMDS"
exit 1
fi
. ${VENV}/bin/activate
shift 1
echo "Executing $@ in ${VENV}"
exec "$@"
@jasonwryan
jasonwryan / Install
Last active April 29, 2021 09:26
Arch Linux installation procedure for LVM on LUKS: UEFI EFISTUB boot with gumiboot on a Samsung Series 9 laptop.
# Notes for installing on Samsung Series 9
# UEFI boot: LVM on LUKS
#
# See the full blog post:
# http://jasonwryan.com/blog/2013/01/25/uefi/
# check you are booted in uefi
modprobe efivars
ls /sys/firmware/efi/vars
@fsbs
fsbs / pycurl_multi_socket_action.py
Created September 16, 2019 15:13
Example of driving transfers with pycurl's multi.socket_action
import asyncio
import pycurl
import selectors
MULTI = pycurl.CurlMulti()
SELECTOR = selectors.DefaultSelector()
LOOP = asyncio.get_event_loop()
TIMER = None
@astanin
astanin / rmtweets.py
Created November 13, 2012 16:31
Delete tweets older than X days.
#!/usr/bin/env python2
"""Delete tweets older than X days.
Usage:
rmtweets.py [at_least_days_old (default=365)]
"""
# Twitter gives access to only the last 3200 tweets, but if you delete
# more recent tweets, then after some time (a week? a month?) the
@kachayev
kachayev / tic-tac-toe.py
Created November 22, 2011 23:50
Tornado demo application: TCP server to tic-tac-toe multiplayer game
"""Simple TCP server for playing Tic-Tac-Toe game.
Use Player-to-Player game mode based on naming auth.
No thoughts about distribution or pub/sub mode
(for monitoring or something like this). Just
basic functionality.
"""
import time
import logging