Skip to content

Instantly share code, notes, and snippets.

@uhop
uhop / formatNumber.js
Created June 6, 2009 02:15
Fixing Spymaster's formatNumber()
// How to format big numbers using commas to separate 1000s and abbreviations
// Example: 12345678900 => 12.34B
var numPattern = /^(\d{0,2})(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?$/;
function putCommasIn(s){
return s.match(numPattern).slice(1).join(",").replace(/^\,{1,}/, "").replace(/\,{1,}$/, "");
}
function trimZeroes(s){
return s.replace(/\.?0+$/, "");
@uhop
uhop / Evolution of a Python programmer.py
Created November 21, 2010 20:13
Evolution of a Python programmer
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
@uhop
uhop / admin.py
Created March 14, 2011 00:31
Adding Dojo's rich editor to Django's Admin.
# Example how to add rich editor capabilities to your models in admin.
from django.contrib.admin import site, ModelAdmin
import models
# we define our resources to add to admin pages
class CommonMedia:
js = (
'https://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js',
@uhop
uhop / gist:3259255
Created August 4, 2012 18:41
Bezier Shaders & Vector openGL rendering
@uhop
uhop / gist:3351030
Created August 14, 2012 17:29 — forked from idan/gist:3135754
A Sample Post

Hello there! This is a sample post for gist.io, a super-lightweight writing soapbox for hackers.

Now look up. Further. Above the post title. See that grey text with the gist ID?

Now back to me. That grey text is a link! Open that sucker in a new tab to see the source for this post. Also, I'm on a horse.

This is a major heading

If you peek at it with a web inspector, you'll see that it is a second-level heading. You can use first level headings, but they'll look just like the second level ones, and the gods of the HTML5 outlining algorithm will frown upon you.

@uhop
uhop / minified.js
Last active December 15, 2015 18:19
UMD header
/* UMD.define */ (typeof define=="function"&&define||function(d,f,m){m={module:module,require:require};module.exports=f.apply(null,d.map(function(n){return m[n]||require(n)}))})
(["module", "../main"], function(module, unit){
// module's code
});
/* UMD.require */ (typeof define=="function"&&require||function(d,f,m){m={module:module,require:require};f.apply(null,d.map(function(n){return m[n]||require(n)}))})
(["module", "../main"], function(module, unit){
// module's code
});
* + table {
border-style:solid;
border-width:1px;
border-color:#e7e3e7;
}
* + table th, * + table td {
border-style:dashed;
border-width:1px;
border-color:#e7e3e7;
@uhop
uhop / nginx-webp-sample.conf
Last active May 25, 2024 17:02
Serving WEBP with nginx conditionally.
user www-data;
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
Verifying that +elazutkin is my blockchain ID. https://onename.com/elazutkin
@uhop
uhop / print.html
Last active November 29, 2022 23:35
The way to print slides as PDF.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Multi-page print test</title>
<!--
Print to PDF, landscape, letter size, no margins, enable background graphics.
Tested on Chrome.
-->
<style>