Skip to content

Instantly share code, notes, and snippets.

@mohd-akram
mohd-akram / query_sort.py
Created January 3, 2013 17:28
An intuitive method to sort results in a few lines (Python)
"""This module sorts a list of results based on a query.
If there is an intersection between words in the query and a result, it
is placed near the beginning of the list (based on length of intersection).
If there is no intersection, the position of the query (substring) in the
result (string) is used for sorting. These results are placed toward the end
of the list.
"""
@obeleh
obeleh / gist:4451005
Last active March 10, 2021 09:47
Python autovivicating tree with parent reference (variation of the one-line tree)

I was reading the gist @https://gist.github.com/2012250

I found the autovivification functionality of it pretty cool. If only I could have a parent reference...

Obviously this was not going to be a one-line tree. But that wasn't the goal

A simple variant:

from collections import defaultdict
@NicolasT
NicolasT / nonblocking.py
Last active May 27, 2024 17:03
Using the 'splice' syscall from Python, in this demonstration to transfer the output of some process to a client through a socket, using zero-copy transfers. See 'splice.py'. Usage: 'python splice.py' in one console, then e.g. 'nc localhost 9009' in another. 'nonblocking.py' is a demonstration of using 'splice' with non-blocking IO.
'''
Demonstration of using `splice` with non-blocking IO
Lots of code is similar to 'splice.py', take a look at that module for more
documentation.
'''
import os
import os.path
import errno
@Chase-san
Chase-san / index.php
Last active December 12, 2015 02:18
A very tiny image gallery.
<?php /* Copyright(c) 2013 Robert Maupin. Released under the ZLIB License. */
if(count($_FILES) > 0) {
extract($_FILES['file']);
list($w,$h,$type)=getimagesize($tmp_name);
/*see exif-imagetype() documentation :) */
if(!$type||$type>3||filesize($tmp_name)>1024*200)
exit();
$ext=image_type_to_extension($type,false);
$md5=md5_file($tmp_name);
move_uploaded_file($tmp_name,$n="img/$md5.$ext");
@f-prime
f-prime / gist:4698599
Created February 2, 2013 18:04
The script extracts the link from an ad page.
import urllib
class AdflySkipper:
def __init__(self, url):
self.url = url
def extract(self):
source = urllib.urlopen(self.url).readlines()
for line in source:
@blzaugg
blzaugg / restroomEtiquette.js
Created March 20, 2013 22:17
restroomEtiquette
function restroomEtiquette(you, restroom) {
while (true) {
if (you.needToGo === 1) {
if (you.okayWithUrinals && restroom.urinalAvailable()) {
var urinal = restroom.occupyAvailableUrinal(you);
you.evacuate(urinal);
urinal.flush();
@dypsilon
dypsilon / frontendDevlopmentBookmarks.md
Last active May 5, 2025 13:05
A badass list of frontend development resources I collected over time.
@absurd
absurd / unfalse_poem.py
Last active December 22, 2015 21:29
An unfalse poem that evaluates properly.
# Copyright 2013AD Gallus Absurd
def unfalse_poem():
None is not True or False
for subject in [complex(True,False)]:
subject is not object
for certainty in [complex(False,True)]:
certainty is not Exception
certainty is not license
The Challenge
-------------
Given the following riddle, write a regular expression describing all possible answers,
assuming you never make a move which simply undoes the last one you made.
The Riddle
----------
You are on your way somewhere, taking with you your cabbage, goat, and wolf, as always.
You come upon a river and are compelled to cross it, but you can only carry one of the
three companions at a time. None of them can swim because this isn't THAT kind of riddle.
@AviDuda
AviDuda / README.md
Last active April 23, 2024 10:32
Unmuting Twitch VODs