Skip to content

Instantly share code, notes, and snippets.

View k4nar's full-sized avatar
🌿

Yannick PÉROUX k4nar

🌿
View GitHub Profile
@k4nar
k4nar / fault.py
Created October 24, 2023 14:01
See what happens when a thread segfault in Python
import faulthandler
import threading
import time
def oups():
import ctypes
# Segfault!
ctypes.string_at(0)
@k4nar
k4nar / nuke.sql
Created July 1, 2020 14:00
SQL - Remove every row in a table using DELETE instead of TRUNCATE
CREATE OR REPLACE FUNCTION nuke() RETURNS void AS $$
DECLARE stmt text;
BEGIN
SELECT 'WITH ' || string_agg('_' || table_name || ' AS (DELETE FROM ' || table_name || ')', ', ') || ' SELECT 1'
FROM information_schema.tables
WHERE table_schema = 'public'
AND table_type <> 'VIEW'
INTO stmt;
EXECUTE stmt;

Keybase proof

I hereby claim:

  • I am k4nar on github.
  • I am k4nar (https://keybase.io/k4nar) on keybase.
  • I have a public key whose fingerprint is 87A9 A72E ABF3 3C0B E0BA B36A 28CC 6944 9027 D53A

To claim this, I am signing this object:

@k4nar
k4nar / gist:25dddf2cd6f1590d257d
Last active August 29, 2015 14:10
Circus start callback
import time
import circus
import redis
from tornado import gen
@gen.coroutine
def start_workers(*args, **kwargs):
@k4nar
k4nar / testcase.rs
Last active August 29, 2015 13:56
Type overloading of trait's implementation
pub struct Point {
x: f64,
y: f64,
z: f64
}
impl Mul<Point, Point> for Point {
fn mul(&self, other: &Point) -> Point {
Point {x: self.x * other.x, y: self.y * other.y, z: self.z * other.z}
}
@k4nar
k4nar / testcase.rs
Created February 12, 2014 14:17
Calling trait's static function from trait's implementation
trait Foo {
fn foo() -> int { 10 }
}
struct FooStruct;
impl Foo for FooStruct {
fn bar(&self) {
println!("Foo : {}", Foo::foo());
}
@k4nar
k4nar / download-google-music-collection.py
Created October 19, 2012 09:13
Download all Google Music's collection from user account. Uses gmusicapi (https://github.com/simon-weber/Unofficial-Google-Music-API)
import os
from subprocess import call
from gmusicapi import api
g = api.Api()
print "Loging..."
g.login("email", "password")
print "OK !"
for song in g.get_all_songs():