Skip to content

Instantly share code, notes, and snippets.

View dedsm's full-sized avatar

David De Sousa dedsm

View GitHub Profile
@dedsm
dedsm / videos.js
Created March 7, 2012 14:22 — forked from csabapalfi/videos.js
Download Coursera videos
javascript:(function(){
$('a.lecture-link').each(function (index){
var $lectureLink = $(this);
var videoLink = $lectureLink.attr('href').replace('view','download.mp4');
var subtitleLink = $lectureLink.attr('href').trim().replace('view','subtitles').replace('lecture_id', 'q') + "_en";
var videoName = '\"' + (index+1) + '.' + $lectureLink.text().trim() + '.mp4\"';
var subtitleName = '\"' + (index+1) + '.' + $lectureLink.text().trim() + '.srt\"';
var cookieHeader = ' --header \"Cookie:'+ document.cookie + '\" ';
console.log('curl -L' + cookieHeader + videoLink + ' > ' + videoName);
console.log('curl -L' + cookieHeader + subtitleLink + ' > ' + subtitleName);

Flatten any multi-level nested iterable, and return a new iterable.

Testing:

after installing the requirements, just run py.test tests.py, it will generate several test cases automatically

Example:

import XMonad
import XMonad.Config.Desktop
import XMonad.Config.Mate
import XMonad.Hooks.EwmhDesktops
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.InsertPosition
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.EZConfig(additionalKeysP)
import XMonad.Actions.FloatKeys
@dedsm
dedsm / compiler.py
Created June 11, 2018 12:05
Timescale drop_chunks django support
from django.db.models.sql.compiler import SQLCompiler
from django.db.models.sql.constants import NO_RESULTS
class DropChunkCompiler(SQLCompiler):
def as_sql(self):
result = 'SELECT drop_chunks(interval %s, %s)'
return result, [self.query.interval, self.query.db_table]
def execute_sql(self, result_type=NO_RESULTS, *args, **kwargs):
@dedsm
dedsm / timescale--db--backend--base.py
Last active April 24, 2024 14:15
WeRiot Django Timescale integration
import logging
from django.contrib.gis.db.backends.postgis.base import \
DatabaseWrapper as PostgisDBWrapper
from django.db import ProgrammingError
from .schema import TimescaleSchemaEditor
logger = logging.getLogger(__name__)
@dedsm
dedsm / app.py
Last active September 19, 2024 12:34
Fastapi cache setup
from .initialize import setup_cache
from .connections import connection
@app.on_event('startup')
async def setup_connections():
await setup_cache()
@app.middleware("http")
async def connections_middleware(request, call_next):
@dedsm
dedsm / sway_xmonad_behavior.py
Created August 23, 2022 19:09
This gist is a helper using i3 ipc that makes i3 behave like xmonad in some workspace-related bindings Mod+{w,e,r} and sharing workspaces across all active displays
import argparse
from i3ipc import Connection
sway = Connection()
outputs = [o for o in sway.get_outputs() if o.active]
def focus_monitor(args):
indices = {"left": 0, "center": 1, "right": 2}
orientation = indices[args.orientation]