Skip to content

Instantly share code, notes, and snippets.

View KrisYu's full-sized avatar

Xue Yu KrisYu

View GitHub Profile
@jlindsey
jlindsey / gist:499215
Created July 29, 2010 20:55
Select an image file using a sheet in Cocoa
NSArray *allowedImageFileExtensions = [NSArray arrayWithObjects:@"png",@"jpg",@"jpeg",@"gif",@"bmp",nil];
// ...
- (IBAction)displayImagePickerSheet:(id)sender {
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setAllowedFileTypes:allowedImageFileExtensions];
[panel setDirectory:NSHomeDirectory()];
[panel setAllowsMultipleSelection:NO];
[panel setCanChooseDirectories:NO];
@ryanflorence
ryanflorence / static_server.js
Last active June 10, 2024 02:37
Node.JS static file web server. Put it in your path to fire up servers in any directory, takes an optional port argument.
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);
<?php
$data = (object)array(
"html" => "<foo bar=\"baz\"/> &amp;",
"arabic" => "العربية al-ʿarabiyyah, IPA: [æl ʕɑrɑˈbijjɐ], or عربي ʿarabī",
"hebrew" => "עִבְרִית, Ivrit",
"chinese" => "汉语/漢語 Hanyu; 华语/華語 Huáyǔ; 中文 Zhōngwén",
"korean" => "한국어/조선말",
"japanese" => "日本語 Nihongo",
"umlauts" => "äüöãáàß",
@cslarsen
cslarsen / objc-gcc.m
Created March 20, 2012 19:23
How to compile Objective-C on the command line on Mac OS X
/*
* To compile objective-c on the command line:
*
* gcc -framework Foundation objc-gcc.m
*
* You may have to link with -lobjc or other libs,
* as required.
*/
#import <Foundation/Foundation.h>
@dradtke
dradtke / Makefile
Created April 25, 2012 22:35
Hello World example for Allegro.
CC := gcc
CFLAGS := -g -Wall
LIBS := -lallegro
SOURCES := $(shell find src/ -type f -name "*.c")
OBJECTS := $(SOURCES:.c=.o)
TARGET := game
all: $(SOURCES) $(TARGET)
$(TARGET): $(OBJECTS)
@mikeygee
mikeygee / 01-before.html
Created May 7, 2012 07:45
truncate blog posts in jekyll
<!-- using the truncate filter -->
{% for post in site.posts limit:10 %}
<h2><a href="{{ post.url }}">{{ post.title }}</a></h2>
<span class="post-date">{{ post.date | date: "%B %d, %Y" }}</span>
{% if post.content.size > 2000 %}
{{ post.content | truncatewords: 300 }} <!-- bad! content gives you rendered html and you will truncate in the middle of a node -->
<a href="{{ post.url }}">read more</a>
{% else %}
{{ post.content }}
{% endif %}
@amueller
amueller / km_seg.py
Created June 19, 2012 21:54
Python Golf: k-means based image segmentation
import numpy as np
def km_segmentation(image, n_segments=100, ratio=50, max_iter=100):
# initialize on grid:
height, width = image.shape[:2]
# approximate grid size for desired n_segments
step = np.sqrt(height * width / n_segments)
grid_y, grid_x = np.mgrid[:height, :width]
means_y = grid_y[::step, ::step]
@karl-
karl- / CleanUpWindow.cs
Created November 15, 2012 03:25
New interface for removing unused Unity assets
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Collections;
using System.Collections.Generic;
public class CleanUpWindow : EditorWindow
{
bool groupEnabled = true;
List<string> usedAssets = new List<string>();
@mbinna
mbinna / podforceupdate.sh
Created December 4, 2012 09:43
Clear CocoaPods cache, re-download and re-install all pods
#!/usr/bin/env bash
rm -rf "${HOME}/Library/Caches/CocoaPods"
rm -rf "`pwd`/Pods/"
pod update
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active June 5, 2024 22:16
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application: