Skip to content

Instantly share code, notes, and snippets.

@cpylua
cpylua / once-only.lisp
Created May 13, 2012 13:33
once-only macro in Common Lisp
(defmacro once-only ((&rest names) &body body)
(let ((gensyms (loop for n in names collect (gensym))))
`(let (,@(loop for g in gensyms collect `(,g (gensym))))
`(let (,,@(loop for g in gensyms for n in names collect ``(,,g ,,n)))
,(let (,@(loop for n in names for g in gensyms collect `(,n ,g)))
,@body)))))
(defmacro do-primes ((var start end) &body body)
(once-only (start end)
`(do ((,var (next-prime ,start) (next-prime (1+ ,var))))
@miohtama
miohtama / gist:2821647
Created May 28, 2012 23:30
Sorted datetime objects with Python
# The trick is to pass timedelta object as a sort key and not to use cmp() function
import datetime
def date_key(a):
"""
a: date as string
"""
a = datetime.datetime.strptime(a, '%d.%m.%Y').date()
return a
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active June 21, 2024 01:45
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@possibilities
possibilities / meteor-async.md
Created August 23, 2012 22:53
Meteor Async Guide

From Meteor's documentation:

In Meteor, your server code runs in a single thread per request, not in the asynchronous callback style typical of Node. We find the linear execution model a better fit for the typical server code in a Meteor application.

This guide serves as a mini-tour of tools, trix and patterns that can be used to run async code in Meteor.

Basic async

Sometimes we need to run async code in Meteor.methods. For this we create a Future to block until the async code has finished. This pattern can be seen all over Meteor's own codebase:

@agnoster
agnoster / README.md
Last active April 6, 2024 22:35
My ZSH Theme

agnoster.zsh-theme

A ZSH theme optimized for people who use:

  • Solarized
  • Git
  • Unicode-compatible fonts and terminals (I use iTerm2 + Menlo)

For Mac users, I highly recommend iTerm 2 + Solarized Dark

@junpluse
junpluse / SwipeNavigationController.h
Last active April 26, 2024 08:15
Simple implementation for swipe-to-back/forward UINavigationController
#import <UIKit/UIKit.h>
@interface SwipeNavigationController : UINavigationController <UIGestureRecognizerDelegate>
@property (nonatomic, readonly) NSArray *poppedViewControllers;
- (void)clearPoppedViewControllers;
@property (nonatomic, readonly) UISwipeGestureRecognizer *leftSwipeGestureRecognizer;
@arvearve
arvearve / gist:4158578
Created November 28, 2012 02:01
Mathematics: What do grad students in math do all day?

Mathematics: What do grad students in math do all day?

by Yasha Berchenko-Kogan

A lot of math grad school is reading books and papers and trying to understand what's going on. The difficulty is that reading math is not like reading a mystery thriller, and it's not even like reading a history book or a New York Times article.

The main issue is that, by the time you get to the frontiers of math, the words to describe the concepts don't really exist yet. Communicating these ideas is a bit like trying to explain a vacuum cleaner to someone who has never seen one, except you're only allowed to use words that are four letters long or shorter.

What can you say?

@neonsamurai
neonsamurai / .tern-project.txt
Created February 20, 2014 20:56
Tern project file for Emacs Meteor Tern plugin. loadEagerly is needed, to make code navigation work properly.
{
"libs": ["browser", "underscore", "jquery"],
"plugins": {
"meteor": {}
},
"loadEagerly": ["*.js","*/*.js","*/*/*.js","*/*/*/*.js"],
"dontLoad": [".meteor", ".demeteorized"]
}
@ShamylZakariya
ShamylZakariya / debounce.swift
Created September 4, 2014 21:01
Simple Swift Debouncer
func debounce( delay:NSTimeInterval, #queue:dispatch_queue_t, action: (()->()) ) -> ()->() {
var lastFireTime:dispatch_time_t = 0
let dispatchDelay = Int64(delay * Double(NSEC_PER_SEC))
return {
lastFireTime = dispatch_time(DISPATCH_TIME_NOW,0)
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
@steipete
steipete / UIKit.m
Created November 26, 2014 11:09
- [UIPopoverPresentationController dimmingViewWasTapped:] decompiled with Hopper 3.6.4
void -[UIPopoverPresentationController dimmingViewWasTapped:](void * self, void * _cmd, void * arg2) {
esi = self;
edi = @selector(delegate);
if ([esi delegate] != 0x0) {
eax = [esi delegate];
var_10 = @selector(popoverPresentationControllerShouldDismissPopover:);
eax = [eax respondsToSelector:@selector(popoverPresentationControllerShouldDismissPopover:)];
if (LOBYTE(eax) != 0x0) {
eax = [esi presented];
if (LOBYTE(eax) != 0x0) {