Skip to content

Instantly share code, notes, and snippets.

View jcayzac's full-sized avatar

Julien Cayzac jcayzac

View GitHub Profile
@jcayzac
jcayzac / Convert from iPhone MOV to MP4 preserving metadata.sh
Last active December 29, 2018 08:28
Photo and video command-line editing
# Example
ffm -i video.mov -map_metadata 0 -map 0 -c:v copy -c:a copy -c:s copy -c:d copy -c:t copy -f mp4 video.mp4
# Convert one file
# $1: video.mov
convert-mov-to-mp4() {
(
set -e -u -o pipefail
! [[ "$1" =~ ^(.+)\.[mM][oO][vV]$ ]] || {
local D="${BASH_REMATCH[1]}.mp4" T="${BASH_REMATCH[1]}.tmp.mp4"
@jcayzac
jcayzac / WORKSPACE
Created October 29, 2018 06:10 — forked from jart/WORKSPACE
Google Auto and Dagger Bazel Config
load("@bazel_tools//tools/build_defs/repo:java.bzl", "java_import_external")
java_import_external(
name = "com_google_auto_common",
jar_sha256 = "eee75e0d1b1b8f31584dcbe25e7c30752545001b46673d007d468d75cf6b2c52",
jar_urls = [
"http://domain-registry-maven.storage.googleapis.com/repo1.maven.org/maven2/com/google/auto/auto-common/0.7/auto-common-0.7.jar",
"http://repo1.maven.org/maven2/com/google/auto/auto-common/0.7/auto-common-0.7.jar",
],
licenses = ["notice"], # Apache 2.0

WebP (lossless)

$ cwebp -lossless -z 9 -mt -m 6 -sharp_yuv "$INPUT" -o "$OUTPUT"

WebP (lossy)

$ cwebp -preset photo -q 80 -mt -m 6 -sharp_yuv -metadata none "$INPUT" -o "$OUTPUT"
@jcayzac
jcayzac / README.md
Last active August 9, 2018 01:47
Dark slack theme

Dark Theme for Slack 3.2+ on macOS

Based on widget-/slack-black-theme#60 and Dark Reader's color scheme.

Install

curl -s https://gist.githubusercontent.com/jcayzac/7e66129f4187cef5415c34c67847d112/raw/macos-auto-apply.sh | bash
### Keybase proof
I hereby claim:
* I am jcayzac on github.
* I am jcayzac (https://keybase.io/jcayzac) on keybase.
* I have a public key whose fingerprint is C315 7A20 ADAF 76F4 144B 5E33 4B15 6948 25F4 1E7F
To claim this, I am signing this object:
@jcayzac
jcayzac / pagination.js
Last active June 17, 2018 23:32
Pagination (naive)
const { dump } = require('node-yaml')
function getData(skip, limit, filter) {
const data = [34, 45, 23, 34, 45, 56, 23, 67, 89, 45, 89, 91, 54, 69, 21, 31, 41]
.filter(typeof filter === 'function' ? filter : (x) => x)
.map((x) => ({value: x}))
let result = data.slice(skip, skip + limit)
result.totalCount = data.length
return result
}
/*
* Support for exposing public parts of the API with Swift3-specific names.
* Note: I'm assuming Xcode 9 won't support Swift 2 anymore.
*/
#if __has_attribute(swift_name) && ((__apple_build_version__ >= 9000000) || ((__apple_build_version__ >= 8000000) && (SWIFT_SDK_OVERLAY_DISPATCH_EPOCH >= 2)))
// swift_name() supports nested "context.name" names.
# define JC_SWIFT3_NAME(n) __attribute__((swift_name(#n)))
#else
// swift_name() does not support nested names.
# define JC_SWIFT3_NAME(n)
#import "AppDelegate.h"
/*
* Note our application delegate doesn't implement -applicationDidEnterBackground:, but it doesn't matter.
*/
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(@"Original -application:didFinishLaunchingWithOptions: (self.class is %@)", self.class);
return YES;
}
@jcayzac
jcayzac / strftime.js
Last active March 10, 2016 08:07
strftime.js
// ES6 strftime(3) function that supports FDxcAaBbCdemuwYynt% for en_US only
// (only for dates, not datetimes)
Date.prototype.format = function(f) {
const t=this,p=(v,f)=>v.toString().length==1?f+v:v,Y=t.getFullYear(),mo=t.getMonth()+1,dm=t.getDate(),u=t.getDay(),A=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'][u%7],B=['January','February','March','April','May','June','July','August','September','October','November','December'][mo-1]
return ['%Y-%m-%d','%m/%d/%y','%m/%d/%Y','%a %b %e %Y',A,A.slice(0,3),B,B.slice(0,3),Y/100|0,p(dm,'0'),p(dm,' '),p(mo,'0'),u,u%7,Y,Y%100,'\n','\t','%'].reduce((_, s, i)=>_.replace(new RegExp('%'+'FDxcAaBbCdemuwYynt%'[i],'g'),s),f)
}
// Unit tests
!() => {
var date = new Date('2016-04-02'), assert = require('assert')
@jcayzac
jcayzac / gist.m
Created July 9, 2015 00:18
Fun with embedded.mobileprovision
NSData *provisioningProfile = nil;
NSData *raw = [NSData dataWithContentsOfURL:[NSBundle.mainBundle URLForResource:@"embedded" withExtension:@"mobileprovision"]];
char *start = memmem(raw.bytes,
raw.length,
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0",
47);
if (start) {
char *end = memmem(start,
(uintptr_t)start - raw.length,
"</plist>",