Skip to content

Instantly share code, notes, and snippets.

View yakovkhalinsky's full-sized avatar

Yakov Khalinsky yakovkhalinsky

View GitHub Profile
@yakovkhalinsky
yakovkhalinsky / Enum.coffee
Last active October 25, 2016 05:10
Possible implementation of Enums in Coffeescript
class Enum
constructor: (fields) ->
if !fields?.length or !Array.isArray fields then throw 'Fields must be an array of Strings'
fields.forEach (field) => @[field.toUpperCase()] = field.toUpperCase()
myEnum = new Enum(['ONE', 'TWO'])
console.log 'Enum', myEnum
@yakovkhalinsky
yakovkhalinsky / Enum.js
Last active December 26, 2015 23:19
Possible implementation of Enums in Javascript
var Enum;
module.exports = Enum = (function() {
function Enum(fields) {
var _this = this;
if (!(fields != null ? fields.length : void 0) || !Array.isArray(fields)) {
throw 'Fields must be an array of Strings';
}
fields.forEach(function(field) {
return _this[field.toUpperCase()] = field.toUpperCase();
@yakovkhalinsky
yakovkhalinsky / splitBy.coffee
Last active December 27, 2015 16:59
Split string into an array by specified lengths of characters and pad each element with a specified character. Given a value ```str = 'abcdefg``` Running this function ```splitBy str, 2, '-'``` should produce an array ```['ab', 'cd', 'ef', 'g-']```
# str: The string we wish to split up
# length: how many characters of 'str' should each array element contain
# padWith: what to padd the last element with
splitBy = (str, length, padWith) ->
pad = (str) ->
str = "#{str}#{padWith}" for i in [str.length...length]
str
pad (str.slice i, i+length), length, padWith for i in [0...str.length] by length
@yakovkhalinsky
yakovkhalinsky / WATCHER.js
Last active December 28, 2015 03:39
Function to process an aggregate watch in Angular
var WATCHER = function(oldValues, newValues, map) {
var changes, index, value;
changes = {};
if (Array.isArray(oldValues)) {
for (index in oldValues) {
value = oldValues[index];
if (value !== newValues[index]) {
changes[map[index]] = {
oldVal: oldValues[index]
newVal: newValues[index]
@yakovkhalinsky
yakovkhalinsky / gist:8949059
Last active October 11, 2016 04:41
My Sublime Text User Preferences
{
"caret_style": "phase",
"close_windows_when_empty": false,
"color_scheme": "Packages/Theme - Flatland/Flatland Dark.tmTheme",
"ensure_newline_at_eof_on_save": true,
"flatland_sidebar_tree_xsmall": true,
"flatland_square_tabs": true,
"font_size": 15.0,
"highlight_line": true,
"highlight_modified_tabs": true,
@yakovkhalinsky
yakovkhalinsky / bh_core.sublime-settings
Last active August 29, 2015 13:56
BracketHighlighter User Preferences (ST2 Plugin)
{
"high_visibility_enabled_by_default": true,
"high_visibility_style": "underline",
"high_visibility_color": "__bracket__"
}
@yakovkhalinsky
yakovkhalinsky / styles.less
Last active April 12, 2022 14:31
My Atom editor personal stylesheet
// colour vars (or color if you're American)
@plain-black: #000;
@plain-white: #fff;
@funky-green: #00ff00; // original
.title-bar {
padding: 15px;
letter-spacing: 0.08em;
font-size: 1.1em;
}
@yakovkhalinsky
yakovkhalinsky / coffeelint.json
Created March 24, 2014 01:21
Atom Coffee Lint config
{
"max_line_length": {
"name": "max_line_length",
"value": 120,
"level": "error",
"limitComments": true
}
}
@yakovkhalinsky
yakovkhalinsky / cookieCutter.js
Last active May 9, 2016 07:00
Get value of last cookie item
(function() {
var cookieParts = {};
window.top.document.cookie.split('; ').forEach(cookieCutter);
function cookieCutter(part) { var split = part.split('='); cookieParts[split[0]] = split[1]; }
})();
@yakovkhalinsky
yakovkhalinsky / fake-server.js
Created January 30, 2015 02:09
Node Fake Response Server with HTTPS
var https = require('https');
var fs = require('fs');
var sslOptions = {
key: fs.readFileSync('localhost.key'),
cert: fs.readFileSync('localhost.crt')
};
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";