Skip to content

Instantly share code, notes, and snippets.

sixpetrov

Block or report user

Report or block sixpetrov

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@sixpetrov
sixpetrov / walksync.js
Created Sep 5, 2018 — forked from luciopaiva/walksync.js
List all files in a directory in Node.js recursively in a synchronous fashion
View walksync.js
#!/usr/bin/env node
const
path = require("path"),
fs = require("fs");
/**
* List all files in a directory recursively in a synchronous fashion
*
* @param {String} dir
@sixpetrov
sixpetrov / regex.js
Created Aug 27, 2018 — forked from Integralist/regex.js
The difference between JavaScript's `exec` and `match` methods is subtle but important, and I always forget...
View regex.js
var str = "The quick brown fox jumped over the box like an ox with a sox in its mouth";
str.match(/\w(ox)/g); // ["fox", "box", "sox"]
// match (when used with a 'g' flag) returns an Array with all matches found
// if you don't use the 'g' flag then it acts the same as the 'exec' method.
str.match(/\w(ox)/); // ["fox", "ox"]
/\w(ox)/.exec(str); // ["fox", "ox"]
View gist:79d0856cae71cdcdf7fcba35ee4f1973
# Uses PyWin32 http://timgolden.me.uk/pywin32-docs/win32clipboard.html
import win32clipboard
def get_clipboard():
win32clipboard.OpenClipboard()
data = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
return data
def set_clipboard(text):
View asyncawaitwithouttrycatch.js
async function getData(){
const a = await someFunction().catch((error)=>console.log(error));
const b = await someOtherFunction().catch((error)=>console.log(error));
if(a && b ) console.log("some result")
}
@sixpetrov
sixpetrov / sublime-text-macos-context-menu.md
Created Nov 27, 2017 — forked from idleberg/sublime-text-macos-context-menu.md
“Open in Sublime Text” in macOS context-menu
View sublime-text-macos-context-menu.md

Open in Sublime Text

  • Open Automator
  • Create a new Service
  • Set “Service receives selected” to files or folders in any application
  • Add a Run Shell Script action
  • Set the script action to /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl -n $@
  • Set “Pass input” to as arguments
  • Save as Open in Sublime Text
@sixpetrov
sixpetrov / mac-apps.md
Created Nov 24, 2017 — forked from erikreagan/mac-apps.md
Mac developer must-haves
View mac-apps.md

Mac web developer apps

This gist's comment stream is a collection of webdev apps for OS X. Feel free to add links to apps you like, just make sure you add some context to what it does — either from the creator's website or your own thoughts.

— Erik

@sixpetrov
sixpetrov / app.swift
Created Nov 23, 2017 — forked from lucamarrocco/app.swift
swift osx application without nib
View app.swift
import Cocoa
class WindowController: NSWindowController {
}
class AppDelegate: NSObject {
var mainWindow: NSWindow?
var mainController: NSWindowController?
}
@sixpetrov
sixpetrov / axInfoForProcessIdentifier.m
Created Nov 20, 2017 — forked from gerad/axInfoForProcessIdentifier.m
get the name and path of the frontmost window using the carbon mac os accessibility api
View axInfoForProcessIdentifier.m
// http://stackoverflow.com/questions/2107657/mac-cocoa-getting-a-list-of-windows-using-accessibility-api
// http://stackoverflow.com/questions/853833/how-can-my-app-detect-a-change-to-another-apps-window
// http://cocoatutorial.grapewave.com/tag/axuielementcopyattributevalue/
- (NSDictionary *)axInfoForProcessIdentifier:(NSNumber *)processIdentifier
{
NSMutableDictionary *ret = [NSMutableDictionary dictionaryWithCapacity:2];
pid_t pid = (pid_t) [processIdentifier integerValue];
AXUIElementRef app = AXUIElementCreateApplication(pid);
AXUIElementRef frontWindow = nil;
NSString *title = nil;
@sixpetrov
sixpetrov / GetNameAndTitleOfActiveWindow.scpt
Created Nov 19, 2017 — forked from timpulver/GetNameAndTitleOfActiveWindow.scpt
[AppleScript] Get Name of active window | Returns the name / title of the active (frontmost) window
View GetNameAndTitleOfActiveWindow.scpt
# taken from user Albert's answer on StackOverflow
# http://stackoverflow.com/questions/5292204/macosx-get-foremost-window-title
# tested on Mac OS X 10.7.5
global frontApp, frontAppName, windowTitle
set windowTitle to ""
tell application "System Events"
set frontApp to first application process whose frontmost is true
set frontAppName to name of frontApp
View cpp_color_theme.cpp
/*
* Block comment
*/
#include <vector>
using namespace std; // line comment
namespace foo {
typedef struct Struct {
int field;
You can’t perform that action at this time.