Skip to content

Instantly share code, notes, and snippets.

@6david9
6david9 / cairo.cpp
Created December 28, 2021 08:27
hello world of cairo
#include <iostream>
#include <cairo/cairo.h>
#include <cairo/cairo-quartz.h>
int main(int argc, const char * argv[]) {
cairo_surface_t *surface = cairo_quartz_surface_create(CAIRO_FORMAT_RGB24, 320 * 3.0, 560 * 3.0);
cairo_t *cr = cairo_create(surface);
cairo_set_antialias(cr, CAIRO_ANTIALIAS_BEST);
#!/bin/zsh
arch_name="$(uname -m)"
if [ "${arch_name}" = "x86_64" ]; then
if [ "$(sysctl -in sysctl.proc_translated)" = "1" ]; then
echo "Running on Rosetta 2"
else
echo "Running on native Intel"
fi
@6david9
6david9 / autostart.ahk
Created December 18, 2021 08:20
move autohotkey script to startup folder
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SourceFile = %A_ScriptDir%\shortcuts.ahk
DestFile = %A_Startup%\shortcuts.ahk
FileCopy, %SourceFile%, %DestFile%, true
Run, %A_Startup%
@6david9
6david9 / shortcuts.ahk
Last active December 20, 2021 15:51
simulate emacs nativate operations using auto hot key
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetCapsLockState, AlwaysOff
+!m::SendInput +^m
!s::SendInput ^s
!a::SendInput ^a
#!/usr/bin/env ruby
require "date"
class Date
def weekday
case self.wday
when 0 then "日"
when 1 then "一"
when 2 then "二"
set -g prefix C-g
setw -g mode-keys vi
unbind C-b
bind C-g send-prefix
bind -n C-\ split-window -h
bind -n C-M-\ split-window
bind -n F1 list-keys
@6david9
6david9 / fill_image
Created August 10, 2016 09:46
aspect fill image
- (void)drawRect:(CGRect)rect
{
if (!self.image) {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, self.backgroundColor.CGColor);
CGContextFillRect(context, rect);
return;
}
CGFloat w = CGRectGetWidth(self.frame);
@6david9
6david9 / parse_ipa.py
Created March 25, 2015 07:12
parse ipa
# -*- coding: UTF-8 -*-
import zipfile
import biplist
import tempfile
import shutil
import re
import os
@6david9
6david9 / week
Created March 9, 2015 16:48
计算万年历星期(基姆拉尔森)
#include <stdio.h>
/*
* 基姆拉尔森计算公式
* W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7
*/
int week(int y, int m, int d)
{
if (m < 3) {
m += 12;
@6david9
6david9 / htob
Created October 23, 2014 06:25
hex to binary
str = ARGF.argv[0].strip.downcase
if str.start_with? '0x'
str.delete! '0x'
end
str.each_char do |c|
bin = c.to_i(16).to_s(2)
bin.insert(0, '0' * (4-bin.length)) if bin.length < 4