Skip to content

Instantly share code, notes, and snippets.

ericdke / launch.json
Created December 31, 2020 18:16
VSCode multiple CPP files
View launch.json
"version": "0.2.0",
"configurations": [
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
ericdke / get_pnut_oembed.txt
Created July 30, 2017 14:04
Flow to get an image from a post oembed
View get_pnut_oembed.txt
if the post oembed does NOT have a "url_expires_at" field:
it's not a pnut file, it's safe to use the "url" field from the post oembed
if "url_expires_at" is NOT past:
it's safe to use "url" field from the post oembed
ericdke / emojiImage.swift
Created June 17, 2017 08:56
Swift 4 String extension for converting an emoji to an NSImage. Idea and original code by Daniel Jalkut
View emojiImage.swift
import Cocoa
extension String {
var containsEmoji: Bool {
for scalar in self.unicodeScalars {
switch scalar.value {
case 0x1F600...0x1F64F, // Emoticons
0x1F300...0x1F5FF, // Misc Symbols and Pictographs
ericdke /
Created October 21, 2016 13:55
Count LOCs in Swift/Xcode project, ignoring pods
# Thanks
find . -path ./Pods -prune -o -name "*.swift" -print0 ! -name "/Pods" | xargs -0 wc -l
View EXIF+ColorProfile-NSImage.swift
if let imageSource = CGImageSourceCreateWithURL(fileURL as CFURL, nil) {
let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil)
if let dict = imageProperties as? [String: Any] {
ericdke / random_probability_generator.cpp
Last active October 6, 2020 04:15
C++: random number generator
View random_probability_generator.cpp
#include <iostream>
#include <iomanip>
#include <random>
// this template comes from
template<class Ty = double, class = std::enable_if<std::is_floating_point<Ty>::value>>
class random_probability_generator {
// default constructor uses single random_device for seeding
ericdke / download.cpp
Last active March 23, 2023 05:10
C++: Download a file using HTTP GET and store in in a std::string
View download.cpp
* HTTPDownloader.hpp
* A simple C++ wrapper for the libcurl easy API.
* Written by Uli Köhler (
* Published under CC0 1.0 Universal (public domain)
ericdke / get_int.cpp
Last active August 16, 2016 17:41
C++: get int from console input
View get_int.cpp
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int get_int()
string input;
int num;
getline(cin, input);
ericdke / urlcharsets.txt
Created May 10, 2016 08:16
URL encoding NSCharacterSet characters
View urlcharsets.txt
ericdke / numericSearch.swift
Created March 12, 2016 17:28
Get strings containing non padded numbers sorted properly by numeric order
View numericSearch.swift
let names = ["h8", "h9", "h10", "h11", "h4", "h12", "h5", "h6"]
let result = names.sort { $$1, options: .NumericSearch) == .OrderedAscending }
result // ["h4", "h5", "h6", "h8", "h9", "h10", "h11", "h12"]