Skip to content

Instantly share code, notes, and snippets.

def nearest_square_tuple(val):
nearest_sqrt = int(round(math.sqrt(val)))
nearest_square = nearest_sqrt ** 2
return (nearest_sqrt, nearest_square)
def delta_square_to_val(val, square):
delta = val - square
return delta
def square_decrement_tuple(val):
def create_token(length):
return binascii.b2a_hex(os.urandom(int(length / 2)))
3 hr
Models:
Organizer
Group
Contact
Location
$.ajax('/api/u/', {
type: 'POST',
data: JSON.stringify({}),
headers: {
'X-XSRF-TOKEN': (function() {
var i = document.cookie.indexOf('XSRF-TOKEN') + 11;
return document.cookie.substring( i , i + 32 )
})()
}})
.success(function(r) {
@lorenmh
lorenmh / slugify.js
Last active August 29, 2015 14:16
Sequelize unique slugify function. The model needs to have a slug and title field.
function toSlug(str) {
return str.replace(/[^\w\s\-]/g, ' ')
.split(' ')
.filter(function(substr) {
return (substr.length > 0);
})
.join('-')
;
}
function xhr(params) {
var x = new XMLHttpRequest();
x.open(params.m, params.p, true);
x.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
x.send(params.d !== void 0 ? JSON.stringify(params.d) : void 0);
x.onload = function() {
params.fn(x.responseText);
}
};
<?php
$pdo=new PDO("mysql:dbname=markers;host=127.0.0.1","root","");
$stmt = $pdo->query("SELECT * FROM markers");
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($results);
#include <stdio.h>
int main() {
int a[4] = { 2, 4, 8, 16 };
int* b = (int *) a;
b++;
printf("%d", (* b));
@lorenmh
lorenmh / clean_branches.sh
Created May 25, 2016 18:14
clean branches from current git directory
#!/bin/bash
# Loren - 2/12/16
# you can provide some grep regex as the first arg if you want to delete only
# specific branches
if [ $1 ]
then
branches="git branch | sed 's/^\*//' | grep $1"
else
function* echoGenerator() {
let received = null;
while (true) {
received = yield received;
if (received === null) return;
received = 'ECHO ' + received;
}