Skip to content

Instantly share code, notes, and snippets.

@dnnta
dnnta / web-fonts-asset-pipeline.md
Created June 17, 2019 16:46 — forked from anotheruiguy/web-fonts-asset-pipeline.md
Custom Web Fonts and the Rails Asset Pipeline

Web fonts are pretty much all the rage. Using a CDN for font libraries, like TypeKit or Google Fonts, will be a great solution for many projects. For others, this is not an option. Especially when you are creating a custom icon library for your project.

Rails and the asset pipeline are great tools, but Rails has yet to get caught up in the custom web font craze.

As with all things Rails, there is more then one way to skin this cat. There is the recommended way, and then there are the other ways.

The recommended way

Here I will show how to update your Rails project so that you can use the asset pipeline appropriately and resource your files using the common Rails convention.

@dnnta
dnnta / city.rb
Created April 20, 2017 09:56
中国城市列表整理
# 数据来源 http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/201703/t20170310_1471429.html
# 截止 2016 年 7 月 31 日
# 4 个直辖市下面的市辖区手动处理, 改为对应的名字,如 北京市-市辖区 改为 北京市-北京
# 其他市辖区, 直接去掉, 不入库
# 还有 4 个省直辖县级行政区划也手动处理, 去掉层级关系
class CreateChinaCities < ActiveRecord::Migration[5.0]
def change
create_table :china_cities do |t|
t.integer :code, index: true
@dnnta
dnnta / run script
Created September 26, 2016 08:36
target run script
lib_name="InjectDebug.dylib"
lib_path="${BUILT_PRODUCTS_DIR}/${lib_name}"
root_path="$(pwd)"
resources_path="${root_path}/Resources"
bundleIDentifier=com.tencent.yzb
rm -rf "${BUILT_PRODUCTS_DIR}/${TARGET_NAME}.app"
cp -rf "${resources_path}/${TARGET_NAME}.app" "${BUILT_PRODUCTS_DIR}/"
chmod 777 "${BUILT_PRODUCTS_DIR}/${TARGET_NAME}.app/YXLiveVideoApp"
#define _DD_MACRO_SELF_STR(macro) #macro
#define _DD_MACRO_TO_STR(macro) _DD_MACRO_SELF_STR(macro)
#define DD_LOG_MACRO(macro) NSLog(@"\n%s\n%s", #macro, _DD_MACRO_TO_STR(macro))
@dnnta
dnnta / layer.m
Created July 14, 2014 05:48
Pause and resume CABasicAnimations
-(void)pauseLayer:(CALayer*)layer
{
CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
layer.speed = 0.0;
layer.timeOffset = pausedTime;
}
-(void)resumeLayer:(CALayer*)layer
{
CFTimeInterval pausedTime = [layer timeOffset];
@dnnta
dnnta / UIView+Frame.h
Last active August 29, 2015 14:03
UIView Frame Category
//
// UIView+Frame.h
//
//
// Created by xxxx on 14-5-28.
// Copyright (c) 2014年 TBJ. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
void method1(NSArray *numbers)
{
NSArray *sorted = [numbers sortedArrayUsingSelector:@selector(compare:)];
}
void method2(NSArray *numbers)
{
NSNumber *max=[numbers valueForKeyPath:@"@max.doubleValue"];
static NSInteger currentTopVisibleSection = -1;
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSIndexPath *topCellPath = [[tableView indexPathsForVisibleRows] objectAtIndex:0];
if (currentTopVisibleSection != topCellPath.section) {
currentTopVisibleSection = topCellPath.section;
NSLog(@"current section on top is %d", currentTopVisibleSection);
}
NSString *header = [NSString stringWithFormat:@"Section %d", section];
@dnnta
dnnta / NSArray+ NullReplacement
Created May 28, 2014 05:30
NSDictionary或者NSArray中Null处理 Replace all NSNull objects in an NSDictionary http://stackoverflow.com/questions/8075147/replace-all-nsnull-objects-in-an-nsdictionary#16702060
#import "NSArray+NullReplacement.h"
#import "NSDictionary+NullReplacement.h"
@implementation NSArray (NullReplacement)
- (NSArray *)arrayByReplacingNullsWithBlanks {
NSMutableArray *replaced = [self mutableCopy];
const id nul = [NSNull null];
const NSString *blank = @"";
for (int idx = 0; idx < [replaced count]; idx++) {
@dnnta
dnnta / gist:4971848
Created February 17, 2013 15:18
判断是否Debugger环境
static bool debuggerRunning(void)
{
int junk;
int mib[4];
struct kinfo_proc info;
size_t size;
info.kp_proc.p_flag = 0;
mib[0] = CTL_KERN;