Skip to content

Instantly share code, notes, and snippets.

@ericvoid
ericvoid / README.markdown
Last active December 15, 2015 10:59 — forked from gudbergur/README.markdown
Bootstrap Typeahead with three new features: selectfist option, source function call debounce and template support.

This is a fork of Bootstrap Typeahead that adds some more modifications.

Selectfirst: false

  $('.typeahead').typeahead({
    source: MYDATA

    // Typeahead will not select the first suggestion.
    // If the user press enter without selecting any suggestion
    // the onselect function will be called with the inputted text
@ericvoid
ericvoid / array.prototype.additions.js
Last active December 17, 2015 15:19
Any and All methods in arrays (lists and collections) are handy and expressive. This gist is an implementation of them for JavaScript. The tests explains their usage.
(function (Array) {
var isFunction = function (value) {
var getType = {};
return value && getType.toString.call(value) === '[object Function]';
};
var anyItemMeetsPredicate = function (items, predicate) {
for (var i=0; i < items.length; i++) {
if (predicate(items[i]) === true) {
@ericvoid
ericvoid / django_object_clone.py
Created October 7, 2016 00:20
Django Object Clone
from django.db import models
class djobjclone(object):
"""
Makes a clone of a django model object.
The clone is shallow and handicapped.
"""
def __init__(self, o):
assert isinstance(o, models.Model)
@ericvoid
ericvoid / myprofiler.cs
Created May 11, 2018 23:09
Simple C# Profiler
public class MyProfiler
{
public int Calls
{
get;
private set;
}
public TimeSpan TotalTime
{
@ericvoid
ericvoid / MultipartFormBuilder.cs
Last active August 1, 2023 21:31
C# WebClient Multipart Form Upload
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace WebClientMultipartExtension
{
public class MultipartFormBuilder
{
static readonly string MultipartContentType = "multipart/form-data; boundary=";
@ericvoid
ericvoid / readme.md
Last active September 14, 2020 21:18
replace.py - A tool to find-and-replace text in files using regex

The most simple usage is as follows:

$ replace.py 'foobarz' 'foo bar' myfile.txt

The tool searches for foobarz on the contents of myfile.txt and replaces it with foo bar. The result is written on stdout. This is useful to check if the script is doing what you expect.

If you want the tool to change de file itself, use the -I argument (use backups or versioning to avoid losing data):

@ericvoid
ericvoid / PhpChainedComparisons.md
Created March 19, 2022 20:58
PHP Chained Comparisons

Python has a synthax to chain comparison operators. For example:

    if x > y > z:
        print('foo')

    if x < y < z:
        print('bar')

    if x == y == z: