Skip to content

Instantly share code, notes, and snippets.

View UncleBill's full-sized avatar
😳
K.I.S.S

UncleBill

😳
K.I.S.S
View GitHub Profile
@Marak
Marak / 0-primeFactor.js
Last active October 12, 2015 03:58
Experimenting with new process.prevTick() API
//
// Calculating prime factors in polynomial time using node.js process.prevTick()
//
// see: http://en.wikipedia.org/wiki/Prime_factor
// see: http://en.wikipedia.org/wiki/Novikov_self-consistency_principle
//
// Authors:
// http://jesusabdullah.net/
// http://marak.com
//
@pekkaklarck
pekkaklarck / gist:6712255
Last active May 23, 2016 01:05
Javascript implementation of UTF-8 decoding algorithm by Björn Höhrmann explained at http://bjoern.hoehrmann.de/utf-8/decoder/dfa/. To support codepoints outside the Unicode BMP, this algorithm uses the custom String.fromCodePoint method explained at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromChar…
var UTF8_ACCEPT = 0;
var UTF8D = [
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
10,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3, 11,6,6,6,5,8,8,8,8,8,8,8,8,8,8,8,
@cowboy
cowboy / iife-variations.js
Created December 24, 2010 00:14
A few variations on writing an IIFE
// Want to learn more about Immediately Invoked Function Expressions? Read
// this article first:
//
// http://benalman.com/news/2010/11/immediately-invoked-function-expression/
// Parens are used to tell the parser that it's a function expression,
// not a function declaration. If you don't explicitly tell the parser to
// expect an expression, it will throw a SyntaxError exception because it
// sees a function declaration without a name specified.
@k0f1sh
k0f1sh / zone-pgm-rainbow
Last active April 27, 2018 15:51
虹色zone
;; zone-pgm-rainbow
(defun decimal->hex (n)
(format "%02X" n))
(defun hsv->rgb (h s v)
(let ((h (max 0 (min 360 h)))
(s (/ (max 0 (min 100 s)) 100.0))
(v (/ (max 0 (min 100 v)) 100.0)))
(if (= 0 s)
local wibox = require( "wibox" )
local awful = require( "awful" )
local rad_tag = require( "radical.impl.common.tag" )
local beautiful = require( "beautiful" )
local radical = require( "radical" )
local rad_task = require( "radical.impl.tasklist" )
local chopped = require( "chopped" )
local collision = require( "collision" )
local color = require( "gears.color" )
local infobg = require( "radical.widgets.infoshapes" )
@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
@preshing
preshing / sort1mb.cpp
Created October 25, 2012 11:28
Sort one million 8-digit numbers in 1MB RAM
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
typedef unsigned int u32;
typedef unsigned long long u64;
//-------------------------------------------------------------------------
// WorkArea
//-------------------------------------------------------------------------
@avafloww
avafloww / PhpJava.java
Last active October 16, 2022 18:50
This snippet of code is syntactically valid in both PHP and Java, and produces the same output in both.
/*<?php
//*/public class PhpJava { public static void main(String[] args) { System.out.printf("/*%s",
//\u000A\u002F\u002A
class PhpJava {
static function main() {
echo(//\u000A\u002A\u002F
"Hello World!");
}}
//\u000A\u002F\u002A
PhpJava::main();
@mwunsch
mwunsch / emoji_image_replace.js
Last active August 13, 2023 21:44
Detect emoji unicode on a page, replace it with images (supplied by GitHub, for now). Goes great in your ~/.js
/**
*
* Here's a thing that will look through all the text nodes of a document, and
* upon encountering an emoji codepoint, will replace it with an image.
* For now, those images are pulled from GitHub, which isn't very nice, so I
* need to find a more suitable host.
*
* Much of this code was gleaned from staring at the minified GitHub JS.
*
* Copyright (c) 2013 Mark Wunsch. Licensed under the MIT License.
@olasitarska
olasitarska / pgessays.py
Created November 18, 2012 10:11
Builds epub book out of Paul Graham's essays.
# -*- coding: utf-8 -*-
"""
Builds epub book out of Paul Graham's essays: http://paulgraham.com/articles.html
Author: Ola Sitarska <ola@sitarska.com>
Copyright: Licensed under the GPL-3 (http://www.gnu.org/licenses/gpl-3.0.html)
This script requires python-epub-library: http://code.google.com/p/python-epub-builder/
"""