Skip to content

Instantly share code, notes, and snippets.

View tlkahn's full-sized avatar
🥫

JG tlkahn

🥫
View GitHub Profile
@tlkahn
tlkahn / gist:4b26ddbba4cb63ff5f9c8418b61febd8
Created June 14, 2017 05:53
Hackerland Radio Transmitters python
def solution(k, arr, origin=0):
arr = sorted(list(set(arr)))
result = 1
cur = 0
origin = 0
for i in range(1, len(arr)):
f = False
if arr[i] - arr[origin] <= k:
@tlkahn
tlkahn / gist:01c304891e5aa6d7562feb0857a81811
Last active June 14, 2017 04:23
hackerland-radio-transmitters
def solution(k, arr, origin=0):
arr.sort()
result = 1
cur = 0
origin = 0
for i in range(1, len(arr)):
if arr[i] - arr[origin] <= k:
pass
else:
@tlkahn
tlkahn / vimregex-juan_auras_lester.md
Created March 15, 2017 13:33 — forked from dreftymac/vimregex-juan_auras_lester.md
vim regular expressions for perl regex fans

Overview

Vim regular expressions are powerful, but they pre-date Perl.

This can be frustrating since the Perl-flavored-regex syntax has expanded beyond into other programming languages and contexts, becoming a de-facto standard.

This guide is a quick cheatsheet and tipsheet for using regular expressions in Vim for those who may be more familiar with Perl.

Quick examples for vimmers who like Perl regex

(require 'package)
(setq package-archives '(("ELPA" . "http://tromey.com/elpa/")
("gnu" . "http://elpa.gnu.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/")))
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
(package-initialize)
;; (package-refresh-contents)
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/") t)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/") t)
(package-initialize)
;;(package-refresh-contents)
(require 'ido)
(ido-mode t)
@tlkahn
tlkahn / main.cpp
Created October 5, 2016 07:25
create a closure in C++
struct db_sum: public std::unary_function<boost::any, void> {
private:
double& sum_;
public:
explicit db_sum(double& sum)
: sum_(sum)
{}
void operator()(const cell_t& value) {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, screenWidth-50, screenWidth-50, 50)];
label.backgroundColor = [UIColor whiteColor];
label.text = @"hello world";
[imageView addSubview:label];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageURL]]]];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.backgroundColor = [UIColor blueColor];
@tlkahn
tlkahn / adt.c
Created June 17, 2016 22:21 — forked from hosaka/README.md
Abstract Data Type using opaque pointers in C
#include <stdio.h>
#include <stdlib.h>
#include "array_api.h"
// abstract array data type types
// opaque pointer:
// an ADT implementation hidden behind the interface that is abstract to
// the client, making it easier to maintain, apply changes and improve
// in this example the array_t data type provides a bunch of functins
@tlkahn
tlkahn / test.mm
Created May 18, 2016 04:10 — forked from drodriguez/test.mm
Objective-C++ NSString wrapper example
// $ g++ -o test -framework Foundation -Wall test.mm
// $ ./test
// The string length is 12
// The string third char value is 108
// The string is Hello World!
#include <iostream>
#import <Foundation/Foundation.h>
class MyCppNSStringWrapper