Skip to content

Instantly share code, notes, and snippets.

View sumeet's full-sized avatar

Sumeet Agarwal sumeet

  • San Francisco, CA
View GitHub Profile
from __future__ import with_statement
import inspect
class Test(object):
def __init__(self, name):
self.name = name
def __enter__(self):
return self
@zeedark
zeedark / gist:1639124
Created January 19, 2012 09:55
Resize a UIButton according to its title's length.
// Resize a UIButton according to its title's length.
CGSize stringSize = [self.myButton.titleLabel.text sizeWithFont:self.myButton.titleLabel.font];
CGRect frame = self.myButton.frame;
frame.size.width = stringSize.width;
[self.myButton setFrame:frame];
@sartak
sartak / a.md
Last active June 26, 2024 04:59
Anki 2 annotated schema
@jordan-brough
jordan-brough / git-recent
Last active June 27, 2024 21:22
Git: Display a list of recently checked out branches/tags/commits
#!/usr/bin/env bash
# Source: https://gist.github.com/jordan-brough/48e2803c0ffa6dc2e0bd
# See also: https://stackoverflow.com/a/25095062/58876
# Download this script as "git-recent" (no extension), chmod it to be executable and put it in your
# path somewhere (e.g. /usr/bin). You can then use it via `git recent` from inside any git repo.
# Examples:
@mlynch
mlynch / Undo.md
Last active April 9, 2024 11:28
Undo/Redo

Undo/Redo

Undo/Redo is one of those features of an application that you almost always need to have if you are building serious GUI tools for people to do work.

The best way to look at undo/redo is two stacks of operations the user has performed:

  • The Undo stack is the "history" of what they've done
  • The redo stack is the breadcrumbs back to the initial state before they started undoing
@akesterson
akesterson / gist:5eb9b223db4cfa3d22d4
Created January 25, 2015 02:26
8086 bootloader / kernel "load from disk and jump to kernel" problem
##### First we build from scratch ...
#######################################
akesterson@akesterson-pc:~/source/upstream/git/akesterson/piquant$ make clean all
rm -f boot.bin asm/*o src/*o
bcc -ansi -3 -c -o src/kernel.o src/kernel.c
ld86 -T0x1000 -M -o kernel.bin src/kernel.o
kernel _printString 0 0000101b R
kernel _main 0 00001049 R
kernel _printChar 0 00001000 R
@mwender
mwender / impbcopy.m
Last active June 20, 2024 09:20
Command line copy an image file to the clipboard in Mac OS X. See first comment for install instructions.
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import <unistd.h>
BOOL copy_to_clipboard(NSString *path)
{
// http://stackoverflow.com/questions/2681630/how-to-read-png-image-to-nsimage
NSImage * image;
if([path isEqualToString:@"-"])
{
// http://caiustheory.com/read-standard-input-using-objective-c
@joshuawscott
joshuawscott / redis_slowlog.rb
Last active August 6, 2017 10:01
Get Redis Slowlog Entries and parse them
# [[87283, 1442412746, 18052, ["hincrby", "191320:2015-09-16", "2015-09-16T13:39:00.000Z", "1"]], [87282, 1442411252, 22037, ["setex", "sifi_session:da34d588e031730b84a0462538022c60", "604800", "\u0004\b{\u0000"]], [87281, 1442410521, 81575, ["scan", "0", "MATCH", "CampaignStatistic:*", "COUNT", "1000"]], [87280, 1442409284, 12309, ["hincrby", "167569:2015-09-16", "2015-09-16T12:57:00.000Z", "1"]], [87279, 1442409279, 11073, ["hincrby", "163562:2015-09-16", "2015-09-16T12:55:00.000Z", "1"]], [87278, 1442409206, 14440, ["hincrby", "163558:2015-09-16", "2015-09-16T12:40:00.000Z", "1"]], [87277, 1442409198, 14750, ["hincrby", "187840:2015-09-16", "2015-09-16T12:34:00.000Z", "1"]], [87276, 1442409180, 11376, ["hincrby", "127478:2015-09-16", "2015-09-16T12:07:00.000Z", "1"]], [87275, 1442405559, 18445, ["hincrby", "182934:2015-09-16", "2015-09-16T11:13:00.000Z", "1"]], [87274, 1442405558, 57467, ["hincrby", "17342:2015-09-16", "2015-09-16T11:03:00.000Z", "1"]]]
require 'redis'
class Entry
attr_reader :log_numbe
@hunterbridges
hunterbridges / twitch_irc.md
Last active May 26, 2024 13:02
How to connect to Twitch with an IRC client (As of Oct 2015)

HOWTO

Connect to Twitch.tv chat with an IRC client

  1. Visit this website and get an OAuth Token for your Twitch account.
  2. Add a server to your IRC client with this configuration, using your OAuth Token as the server password. Make sure it is not using SSL.
{
  address = "irc.twitch.tv";
chatnet = "Twitch";
@tikolakin
tikolakin / fish_alias.md
Last active May 2, 2024 14:21
Create alias in Fish shell and save this as a permanent function

Directly from CLI

alias x='exit'
funcsave x

or create a file in

~/.config/fish/functions 

with name