Skip to content

Instantly share code, notes, and snippets.

int64_t ipow(int64_t base, uint8_t exp) {
static const uint8_t highest_bit_set[] = {
0, 1, 2, 2, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 255, // anything past 63 is a guaranteed overflow with base > 1
@pkorac
pkorac / leafletGeoJsonTileLayer.js
Last active December 16, 2018 07:43
A really simple GeoJSON tile layer in Leaflet solution The original idea belongs to Koko A. but this is a really simple and minimal piece of code I found if you want to use tiled json layers in leaflet.js Read more about it below (in the script) and be sure that your coordinates are good in the geojson files (i.e. in the right projection).
/*
# GEOJSON TILE LAYER IN LEAFLET.JS
The original idea for this gist comes from Koko A.'s post on leaflet-js google groups
(https://groups.google.com/forum/#!msg/leaflet-js/d7ur-evSz7Q/p_B4ea_0K1AJ)
Use it at your own peril (•
## The basic concept
- setup the map and the tiles as usual
- respond to the "tileload" event with a function that loads the json file (that has the same name - z, x, y - as the tile)
@mrchief
mrchief / LICENSE.md
Last active March 23, 2024 12:28
Add "Open with Sublime Text 2" to Windows Explorer Context Menu (including folders)

MIT License

Copyright (c) [year] [fullname]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

@jonathansp
jonathansp / sptrans.py
Created November 15, 2013 20:50
Um cliente python para a API Olho Vivo da SPTrans de São Paulo
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
""" Um cliente python para a API Olho Vivo """
import requests
class SPTransClient(object):
""" Um cliente python para a API Olho Vivo """
@wwwtyro
wwwtyro / gist:beecc31d65d1004f5a9d
Created March 16, 2015 05:54
GLSL ray-sphere intersection
float raySphereIntersect(vec3 r0, vec3 rd, vec3 s0, float sr) {
// - r0: ray origin
// - rd: normalized ray direction
// - s0: sphere center
// - sr: sphere radius
// - Returns distance from r0 to first intersecion with sphere,
// or -1.0 if no intersection.
float a = dot(rd, rd);
vec3 s0_r0 = r0 - s0;
float b = 2.0 * dot(rd, s0_r0);
@karpathy
karpathy / min-char-rnn.py
Last active July 18, 2024 15:59
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@Vedolin
Vedolin / sptrans.py
Created January 27, 2016 15:02 — forked from jonathansp/sptrans.py
Um cliente python para a API Olho Vivo da SPTrans de São Paulo
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
""" Um cliente python para a API Olho Vivo """
import requests
class SPTransClient(object):
""" Um cliente python para a API Olho Vivo """
@TheSalarKhan
TheSalarKhan / transform.py
Created March 23, 2016 22:19
Perspective transformation using Open CV and Python
# This script does a perspective transformation with an A4 paper
# Get an A4 sheet, put it on a table in front of your webcam
# just close enough so that all its corners are visible.
# Run this script, you will be given a frame from the webcam.
# Pick the corners of the A4 sheet for the software, by double clicking on its corners
# one by one in the following order: top left, top right, bottom left, bottom right.
# Just as you select the last corner, a live feed without the perspective distortion
# shows up and now you can write something on it, and have a view of it as if
# the camera was right on top of it. Cheers!
# visit:
@diegopacheco
diegopacheco / pip3-python3-ubuntu.md
Created January 5, 2017 13:46
How to Install pip3 on python3 Ubuntu 16.04
sudo apt-get install python3-setuptools
sudo easy_install3 pip
@chrisveness
chrisveness / crypto-sha.js
Last active July 20, 2023 04:45
Uses the SubtleCrypto interface of the Web Cryptography API to hash a message using SHA-256.
/**
* Returns SHA-256 hash from supplied message.
*
* @param {String} message.
* @returns {String} hash as hex string.
*
* @example
* sha256('abc').then(hash => console.log(hash));
* const hash = await sha256('abc');
*/