Skip to content

Instantly share code, notes, and snippets.

View flavienbwk's full-sized avatar

Flavien Berwick flavienbwk

  • Berwick IT
  • Montréal, Canada
  • 11:12 (UTC -04:00)
View GitHub Profile
@vdel26
vdel26 / nginx_basicauth.lua
Last active November 13, 2022 18:22
Extracting Basic Auth token
--[[
Authorization logic
]]--
function get_auth_params(where, method)
local params = {}
if where == "headers" then
params = ngx.req.get_headers()
elseif where == "basicauth" then
@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()
@yarl
yarl / geoportal-tms.php
Created January 2, 2014 18:32
Geoportal WMS to TMS conversion.
<?php
$zoom = htmlspecialchars($_GET["zoom"]);
$x = htmlspecialchars($_GET["x"]);
$y = htmlspecialchars($_GET["y"]);
//explanation: https://gist.github.com/tmcw/4954720
$y = pow(2, $zoom)-$y-1;
//source: https://github.com/timwaters/whoots/blob/master/whoots.rb
@raveren
raveren / cryptographically_secure_random_strings.php
Last active November 21, 2023 12:35
Generate cryptographically secure random strings. Based on Kohana's Text::random() method and this answer: http://stackoverflow.com/a/13733588/179104
function random_text( $type = 'alnum', $length = 8 )
{
switch ( $type ) {
case 'alnum':
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'alpha':
$pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'hexdec':
@asabaylus
asabaylus / gist:3071099
Created July 8, 2012 14:12
Github Markdown Heading Anchors

Anchors in Markdown

To create an anchor to a heading in github flavored markdown. Add - characters between each word in the heading and wrap the value in parens (#some-markdown-heading) so your link should look like so:

[create an anchor](#anchors-in-markdown)

@stevedoyle
stevedoyle / cpu_freq
Last active February 12, 2024 01:01
Get CPU frequency (Linux platforms - /proc/cpuinfo)
#include <iostream>
#include <fstream>
#include <string>
#include <stdint.h>
#include <pcre.h>
using namespace std;
uint32_t cpufreq()
{