View insert-into-sorted-array.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1d array | |
for (var i = 0, len = arr.length; i < len; i++) { | |
if (somevalue < arr[i]) { | |
arr.splice(i, 0, somevalue); | |
break; | |
} | |
} | |
return arr; |
View insert-into-sorted-array.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1d array | |
for (var i = 0, len = arr.length; i < len; i++) { | |
if (somevalue < arr[i]) { | |
arr.splice(i, 0, somevalue); | |
break; | |
} | |
} | |
return arr; |
View flatten.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Iterable, Mapping | |
from operator import methodcaller | |
def flatten(it, map_iter='values', max_depth=128): | |
if max_depth < 0: | |
try: | |
raise RecursionError('maximum recursion depth exceded in flatten') | |
except NameError: | |
raise Exception('maximum recursion depth exceded in flatten') | |
elif isinstance(it, str): |
View sdl_v2.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void DrawSurfaceToScreen() | |
{ | |
int n = _num_dirty_rects; | |
if (n == 0) return; | |
_num_dirty_rects = 0; | |
if (n > MAX_DIRTY_RECTS) { | |
SDL_CALL SDL_UpdateTexture( | |
_sdl_texture, NULL, _sdl_surface->pixels, _sdl_surface->pitch); |
View sdl_v1.2.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void DrawSurfaceToScreen() | |
{ | |
int n = _num_dirty_rects; | |
if (n == 0) return; | |
_num_dirty_rects = 0; | |
if (n > MAX_DIRTY_RECTS) { | |
if (_sdl_screen != _sdl_realscreen) { | |
SDL_CALL SDL_BlitSurface(_sdl_screen, NULL, _sdl_realscreen, NULL); | |
} |
View gist:5cb72bc5f5bc64567e66a3f17b4b834a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let q = orbitGroup.quaternion.clone(); | |
const rotation = new THREE.Quaternion(); | |
rotation.setFromAxisAngle(new THREE.Vector3(1, 0, 0), -Math.PI / 2); | |
q.multiply(rotation); | |
orbitPlane.normal.set(0, 0, 1).applyQuaternion(q); |
View lerp-color.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A linear interpolator for hex colors. | |
* | |
* Based on: | |
* https://gist.github.com/rosszurowski/67f04465c424a9bc0dae | |
* | |
* @param {Number} a (hex color start val) | |
* @param {Number} b (hex color end val) | |
* @param {Number} amount (the amount to fade from a to b) | |
* |
View array-shuffle.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const shuffleArray = function(array) { | |
const a = array.slice(); | |
for (let i = a.length - 1; i > 0; i--) { | |
const j = Math.floor(Math.random() * (i + 1)); | |
[a[i], a[j]] = [a[j], a[i]]; | |
} | |
return a; | |
}; |
View irssi-autofocus.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/script exec -perm Irssi::signal_add('message public', sub { $_[0]->window_find_name($_[4])->set_active }) |
View gist:7603812
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe Users::OauthCallbacksController, "handle facebook authentication callback" do | |
describe "#annonymous user" do | |
context "when facebook email doesn't exist in the system" do | |
before(:each) do | |
stub_env_for_omniauth | |
get :facebook |
NewerOlder