Skip to content

Instantly share code, notes, and snippets.

@sinelaw
sinelaw / datepicker-focus.js
Last active August 29, 2019 13:46 — forked from jeffsheets/datepicker-focus.js
Fixes reopening of datepicker on IE <= 9 (not tested on IE 10) Changes to work for jQuery 1.9.1 and jQuery-ui 1.10.1: 1. don't use $.browser since it's deprecate. Instead use a var called isIE 2. simplify the handlers 3. use $.datepicker.setDefaults to affect ALL datepickers on the page
/*
After jquery ui datepicker selection, blur and change
events fire before focus is returned to the input field,
handling a quirk from IE browsers
*/
function setupDatepicker() {
// The 'isIE' var below requires an '.old-ie' class to be set on the html,
// for example:
// <!--[if lt IE 7]> <html class="old-ie lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
// <!--[if IE 7]> <html class="old-ie ie7 lt-ie9 lt-ie8"> <![endif]-->
@sinelaw
sinelaw / copy.py
Last active July 2, 2019 18:51
Parallel copy of a single file
import threading
import os
import sys
BLOCK_SIZE = 1024*1024
THREADS = 16
def write_range(source, target, start, amount, block_size):
with open(source, 'r') as source_file:
with open(target, 'r+') as target_file:
@sinelaw
sinelaw / ping.sh
Created April 8, 2015 12:02
parallel ping
cat hosts | xargs -P 0 -n1 -ihost bash -c 'ping -q -W 1 -c 1 host &> /dev/null || echo host failed'
/* license: https://opensource.org/licenses/MIT */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;
namespace Behaviors {
#!/bin/bash
set -eu
BRANCH_A="$1"
shift
BRANCH_B="$1"
shift
PATHS="$@"
BRANCH_A_COMMITS=$(mktemp)
ONLY_IN_BRANCH_A=$(mktemp)
BRANCH_B_COMMITS=$(mktemp)
@sinelaw
sinelaw / atomic.c
Created August 17, 2017 08:01
testing <stdatomic.h> on Intel cross-cacheline
#include <stdint.h>
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdatomic.h>
#define CACHELINE__BYTECOUNT (64)
struct Data {
uint8_t bytes[CACHELINE__BYTECOUNT - 4];
@sinelaw
sinelaw / git-unmerged-commits
Last active June 2, 2016 13:13
Given branch/ref (e.g. my_branch) and target (e.g. origin/master), lists commits in branch that have no "equivalent" ones in target (by author, date and message)
#!/bin/bash
set -eu
# Similar to git branch --merged but looks at commit author, date and
# subject, instead of hash.
#
# Given branch/ref (e.g. my_branch) and target (e.g. origin/master),
# lists commits in branch that have no "equivalent" ones in target (by
# author, date and message).
@sinelaw
sinelaw / binary.hs
Created February 3, 2016 08:39
Binary encode/decode of Fixed
-- run it like:
-- stack ghc --package criterion -- binary.hs -Wall -O2 && ./binary
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE BangPatterns #-}
module Main where
import Data.ByteString.Lazy (ByteString)
import Data.Binary
import Data.Fixed
@sinelaw
sinelaw / tailor.sh
Last active January 2, 2016 04:06
In-place tail: prints the last output line of a command, overriding it in-place
#!/bin/bash -eu
LOG_FILE=$1
SB="stdbuf -i0 -oL"
shift
tput sc
$@ 2>&1 | $SB tee $LOG_FILE | $SB cut -c-$(tput cols) | $SB sed -u 's/\(.\)/\\\1/g' | $SB xargs -0 -d'\n' -iyosi -n1 bash -c 'tput rc;tput el; printf "\r%s" yosi'
EXIT_CODE=${PIPESTATUS[0]}
tput rc;tput el;printf "\r" # Delete the last printed line
exit $EXIT_CODE
interface IGetMethod { int GetValue(); }
interface ISetMethod { void SetValue(int value); }
interface IBothMethods : IGetMethod, ISetMethod { }
class BothMethods : IBothMethods
{
int _value;