Skip to content

Instantly share code, notes, and snippets.

@mkhatib
mkhatib / geo.js
Created May 24, 2013 02:55
A Javascript utility function to generate number of random Geolocations around a center location and in a defined radius.
/**
* Generates number of random geolocation points given a center and a radius.
* @param {Object} center A JS object with lat and lng attributes.
* @param {number} radius Radius in meters.
* @param {number} count Number of points to generate.
* @return {array} Array of Objects with lat and lng attributes.
*/
function generateRandomPoints(center, radius, count) {
var points = [];
for (var i=0; i<count; i++) {
public class PalindromeMaker {
public String make(String baseString) throws Exception{
int[] hash= new int[26];
for(int i=0;i<baseString.length();i++){
char ch=baseString.charAt(i);
if(ch<'A' || ch>'Z') throw new Exception("Wrong Input");
hash[ch-'A']++;
}
boolean check=false;
StringBuilder begin=new StringBuilder();
@arjendk
arjendk / cartodb-install-ubuntu-1204.md
Last active May 20, 2021 13:33
Installing CartoDB on Ubuntu Server 12.04
@leepro
leepro / gist:6408846
Created September 2, 2013 02:55
K-complementary
import java.util.Arrays;
class Solution {
public int solution(int K, int[] A) {
Arrays.sort(A);
return getKC(K, A);
}
public int getKC(int K, int[] A) {
import sys
import cv
class FaceDetect():
def __init__(self):
cv.NamedWindow ("CamShiftDemo", 1)
device = 0
self.capture = cv.CaptureFromCAM(device)
capture_size = (320,200)
cv.SetCaptureProperty(self.capture, cv.CV_CAP_PROP_FRAME_WIDTH, capture_size[0])
//*****************************************************************************
/// @file
/// @brief
/// Arduino SmartThings Shield LED Example
//*****************************************************************************
#include <SoftwareSerial.h> //TODO need to set due to some weird wire language linker, should we absorb this whole library into smartthings
#include <SmartThings.h>
#define PIN_THING_RX 3
@chanks
chanks / gist:7585810
Last active January 10, 2025 03:03
Turning PostgreSQL into a queue serving 10,000 jobs per second

Turning PostgreSQL into a queue serving 10,000 jobs per second

RDBMS-based job queues have been criticized recently for being unable to handle heavy loads. And they deserve it, to some extent, because the queries used to safely lock a job have been pretty hairy. SELECT FOR UPDATE followed by an UPDATE works fine at first, but then you add more workers, and each is trying to SELECT FOR UPDATE the same row (and maybe throwing NOWAIT in there, then catching the errors and retrying), and things slow down.

On top of that, they have to actually update the row to mark it as locked, so the rest of your workers are sitting there waiting while one of them propagates its lock to disk (and the disks of however many servers you're replicating to). QueueClassic got some mileage out of the novel idea of randomly picking a row near the front of the queue to lock, but I can't still seem to get more than an an extra few hundred jobs per second out of it under heavy load.

So, many developers have started going straight t

@ashelly
ashelly / getopt.c
Last active August 25, 2024 03:25
"Port of GNU getopt() to Win32 for anyone who's tired of dealing with getopt() calls in Unix-to-Windows ports." Ported by Pete Wilson. Recovered from the Internet Archive's snapshot of www.pwilson.net/sample.html.
/* Getopt for GNU.
NOTE: getopt is now part of the C library, so if you don't know what
"Keep this file name-space clean" means, talk to [email protected]
before changing it!
Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001
Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@dconnolly
dconnolly / README.md
Last active December 11, 2024 09:10
All 100 Chromecast background images that are rotated through, linked to their original locations on Google hosting. Links to 2560 width versions, where available.
@tsiege
tsiege / The Technical Interview Cheat Sheet.md
Last active May 14, 2025 04:34
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

ANNOUNCEMENT

I have moved this over to the Tech Interview Cheat Sheet Repo and has been expanded and even has code challenges you can run and practice against!






\