Skip to content

Instantly share code, notes, and snippets.

@ismasan
ismasan / gist:464257
Created July 5, 2010 11:30
Event-emitter module for Javascript objects
/* Abstract event binding
Example:
var MyEventEmitter = function(){};
MyEventEmitter.prototype = new AbstractEventsDispatcher;
var emitter = new MyEventEmitter();
// Bind to single event
emitter.bind('foo_event', function(data){ alert(data)} );
@kylefinley
kylefinley / main.coffee
Created November 21, 2011 11:47
SproutCore 20 Routing + Statechart
require 'sproutcore'
require 'sproutcore-statechart'
require 'sproutcore-routing'
App = SC.Application.create()
App.GlobalNavController = SC.Object.create(
home: -> App.statechart.gotoState 'home'
about: -> App.statechart.gotoState 'about'
)
@royosherove
royosherove / gist:4046346
Created November 9, 2012 15:34
simple angular js to search and display youtube videos
<head >
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script>
<script type="text/javascript">
function PhoneListCtrl($scope, $http){
var dataurl ='http://gdata.youtube.com/feeds/api/videos?q="string%20calculator"%20kata%20-tekpub%20-movie&orderby=rating&alt=json';
$http.get(dataurl).success(function(data){
@radianttap
radianttap / gist:4484269
Last active December 10, 2015 19:48 — forked from anonymous/gist:4468522
Pulse view
+ (void)pulseView:(UIView *)view completion:(void (^)(void))block {
// if you use auto layout, view-based transform go haywire, as they trigger layoutSubviews
// consequence is that you have no idea where the view will end up on the screen once animation completes
// see this discussion: http://stackoverflow.com/questions/12943107/how-do-i-adjust-the-anchor-point-of-a-calayer-when-auto-layout-is-being-used
// thus (per solution 4 from link above), rewriting with CAKeyframeAnimation
CAKeyframeAnimation *ka = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
ka.duration = .49;
@sebreh
sebreh / WeakMacros.h
Last active December 11, 2015 21:39
Shorthand macros for creating weak references.
#define SR_WEAK(obj) __typeof__(obj) __weak
#define SR_WEAK_SELF SR_WEAK(self)
// Usage:
// SR_WEAK_SELF weakSelf = self;
$(function() {
var $sidebar = $("#sidebar"),
$window = $(window),
offset = $sidebar.offset(),
topPadding = 20;
$window.scroll(function() {
if ($window.scrollTop() > offset.top) {
$sidebar.stop().animate({
@cherifya
cherifya / UIImageView+Webcache_Animation.c
Last active December 27, 2016 07:10
Improve SDWebImage library with support for a UIActivityIndicator and optional image transition. The transition animation is a simple fade-in.
//
// UIImageView+Webcache_Animation.m
// Tubesmix
//
// Created by Cherif YAYA on 17/03/13.
// Copyright (c) 2013 Cherif YAYA. All rights reserved.
//
#import "UIImageView+Webcache_Animation.h"
@msanders
msanders / NSColor+CGColor.m
Created November 20, 2010 16:11
Category for AppKit that converts an NSColor to a CGColor (ala UIColor in the iOS)
//
// NSColor+CGColor.m
//
// Created by Michael Sanders on 11/19/10.
//
#import "NSColor+CGColor.h"
@implementation NSColor (CGColor)
@jankuca
jankuca / index.js
Created March 17, 2011 09:48
Simple Facebook Graph API Node.js Client
var HTTPS = require('https');
var QueryString = require('querystring');
/**
* Facebook API Wrapper
* @constructor
* @param {Object} info Info about the Facebook application
*/
var Client = function (info) {
if (!info.id) {
- (IBAction)downloadFile:(id)sender {
NSURL *url = [NSURL URLWithString:@"http://www.hulkshare.com/dl/qw30o7x373a8/stan_courtois_&_felly_vs_cutting_crew_-_die_in_your_arms_(x-centrik_mix)_%5B_www.themusix.net_%5D.mp3"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSString *fullPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[url lastPathComponent]];
[operation setOutputStream:[NSOutputStream outputStreamToFileAtPath:fullPath append:NO]];