Skip to content

Instantly share code, notes, and snippets.

View dmitmel's full-sized avatar

Dmytro Meleshko dmitmel

View GitHub Profile
def iter_group(queue):
buf = []
prev_key = None
for val in queue:
cur_key, cur_val = val
#print cur_key, cur_val
if cur_key == prev_key or prev_key is None:
buf.append(cur_val)
else:
@feross
feross / gist:1936829
Created February 29, 2012 01:32
typeracer.com cheat js
// Feross Aboukhadijeh - Apr 12 2010
//
// Script I hacked together to cheat on TypeRacer.com. You use it by waiting for the typing game
// to start. Once it starts, open up Firebug, paste in this code, and run it. Now, just press
// space to auto-type each word. I made the user push space, as opposed to advancing the words
// automatically because I believe the site looks for a keypress event before evaluating the contents
// of the input box. I could not figure out how to fake a user keypress event. Perhaps this is
// disallowed for browser security reasons?
//
// Next todo: Site detects the unbelievable WPM and asks you to do a captcha test.
@hellerbarde
hellerbarde / latency.markdown
Created May 31, 2012 13:16 — forked from jboner/latency.txt
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

#!/usr/bin/awk
BEGIN {
for (i = 0; i <= 255; i++) {
ord[sprintf("%c", i)] = i
}
}
function escape(str, c, len, res) {
len = length(str)
@lucasad
lucasad / urlencode.zsh
Created September 7, 2013 09:40
ZSH urlencode
urlencode() {
setopt localoptions extendedglob
input=( ${(s::)1} )
print ${(j::)input/(#b)([^A-Za-z0-9_.\!~*\'\(\)-])/%${(l:2::0:)$(([##16]#match))}}
}
@bradfrost
bradfrost / gist:59096a855281c433adc1
Last active September 4, 2023 15:01
Why I'm Not A JavaScript Developer

Answering the Front-end developer JavaScript interview questions to the best of my ability.

  • Explain event delegation

Sometimes you need to delegate events to things.

  • Explain how this works in JavaScript

This references the object or "thing" defined elsewhere. It's like "hey, thing I defined elsewhere, I'm talkin' to you."

  • Explain how prototypal inheritance works.
@hitman401
hitman401 / main.rs
Last active April 16, 2024 13:12
Producer Consumer Sample in RUST
use std::sync::{Arc, Mutex, Condvar};
use std::thread;
struct Producer {
cvar: Arc<(Mutex<bool>, Condvar)>
}
impl Producer {
pub fn new(cvar: Arc<(Mutex<bool>, Condvar)>) -> Producer {
Producer {
@svnlto
svnlto / index.js
Created June 4, 2015 07:46
FileReader Promise Helper
const readFile = (file) => {
let reader = new global.FileReader();
return new Promise((resolve, reject) => {
reader.onload = (event) => {
file.data = event.target. result;
resolve(file);
};
reader.onerror = () => {
@yuttie
yuttie / zsh-history-search-with-peco.zsh
Last active June 4, 2021 16:06 — forked from jimeh/zsh-history-search-with-peco.zsh
Use peco (https://github.com/peco/peco) to search ZSH's history via ctrl+R
# Search shell history with peco: https://github.com/peco/peco
# Adapted from: https://github.com/mooz/percol#zsh-history-search
if which peco &> /dev/null; then
function peco_select_history() {
local tac
{ which gtac &> /dev/null && tac="gtac" } || \
{ which tac &> /dev/null && tac="tac" } || \
tac="tail -r"
BUFFER=$(fc -l -n 1 | eval $tac | \
peco --layout=bottom-up --query "$LBUFFER")
@bagonyi
bagonyi / fix.txt
Created March 4, 2016 16:38
OS X El Capitan ZSH order of PATH set in .zshenv is not respected
According to http://www.zsh.org/mla/users/2015/msg00727.html the order gets overwritten by path_helper.
If you move your $PATH settings from ~/.zshenv to ~/.zprofile path_helper won't override your PATH settings.