Skip to content

Instantly share code, notes, and snippets.

@rraallvv
rraallvv / LuaJIT-Xcode-build-phase.sh
Last active August 29, 2015 14:20
Build LuaJIT 2.1
shopt -s extglob
if [ ! -e $BUILT_PRODUCTS_DIR/$EXECUTABLE_NAME ]; then
LUADIR="$SRCROOT/luajit"
mkdir -p $BUILT_PRODUCTS_DIR
for ARCH in $ARCHS ; do
TARGET_ARCH="-m32"
#import <Foundation/Foundation.h>
static NSMethodSignature *BlockSignature(id blockObj) {
struct Block {
void *isa;
int flags;
int reserved;
void *invoke;
#import <dlfcn.h>
#import <Foundation/Foundation.h>
struct BlockDescriptor
{
unsigned long reserved;
unsigned long size;
void *rest[1];
@rraallvv
rraallvv / main.lua
Last active August 29, 2015 14:21 — forked from charles-l/main.lua
-- This gist uses http://luapower.com/objc.html as an FFI. I think it works on it's own, but I would recommend
-- getting the whole LuaPower project, because all the libraries rock.
--
-- This script will open a window that displays two rectangles. One red and one blue.
local glue = require'glue'
local objc = require'objc'
local ffi = require'ffi'
local pp = require'pp'
@rraallvv
rraallvv / ObjC_wrapper_block.m
Created May 16, 2015 23:54
ObjC wrapper block
#import <Foundation/Foundation.h>
#import <objc/message.h>
struct BlockDescriptor {
unsigned long reserved;
unsigned long size;
void *rest[1];
};
struct Block {
@rraallvv
rraallvv / iTunes Sleep Timer.applescript
Last active August 29, 2015 14:21
iTunes Sleep Timer
property lastSleepLength : 5
property fade_for_minutes : 10
global endTime, initialVolume
on idle
-- Wait until fade_for_minutes before the end time
-- Then call fade_sound which will fade the sound, pause itunes, and reset the volume
set curTime to current date
if ((curTime + (fade_for_minutes * 60)) ≥ endTime) then
@rraallvv
rraallvv / remove_code_from_source_with_defines.sh
Last active August 29, 2015 14:21
Remove code from source with defines
#keep code within THEDEFINITION defines
unifdef -DTHEDEFINITION in.c > out.c
#remove code within THEDEFINITION defines
unifdef -UTHEDEFINITION in.c > out.c
@rraallvv
rraallvv / gist:962fe989033279ff5e02
Created June 30, 2015 21:02
Downloading from Apple with curl
curl -b cookies.txt -c cookies.txt <URL> -o <output file> -L -C -
@rraallvv
rraallvv / resample-psi.sh
Created January 27, 2016 12:34
Resample images to 72 DPI using sips
#!/bin/bash
if [[ ! "$1" || "$1" == "-h" || "$1" == "--help" ]]; then cat <<HELP
Resample specified images to 72 DPI
http://benalman.com/
Usage: $(basename "$0") [img [img ...]]
The new MacBook Pro retina display is amazing, but screengrabs taken on
one using the screencapture utility aren't scaled to 72 DPI by default.
This script scales those images to 72 DPI, making them viewable at a sane
resolution in web browsers.
@rraallvv
rraallvv / epub-compression.sh
Created January 27, 2016 12:38
Decompress/compress EPUB e-books
# Decompress files from EPUB e-book
unzip epubfilename.epub
# Compress back to EBUB e-ebook
zip -X newepubname.epub mimetype
zip -rg newepubname.epub META-INF -x \*.DS_Store
zip -rg newepubname.epub OEBPS -x \*.DS_Store