Skip to content

Instantly share code, notes, and snippets.

View necmettin's full-sized avatar

Necmettin Begiter necmettin

View GitHub Profile
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@tsabat
tsabat / zsh.md
Last active July 7, 2024 16:56
Getting oh-my-zsh to work in Ubuntu
@turicas
turicas / attrdict.py
Created December 22, 2011 16:21
Python class with dict-like get/set item
#!/usr/bin/env python
# coding: utf-8
class AttrDict(object):
def __init__(self, init=None):
if init is not None:
self.__dict__.update(init)
def __getitem__(self, key):
return self.__dict__[key]
@jhgaylor
jhgaylor / meteor_download.js
Last active January 18, 2018 10:31
Download files to the filesystem on the meteor server
//given the urls of files to download, store them on the filesystem
function download_all_files (urls, base_destination, job_id, cb) {
var url = urls.shift();
var file_path = path.join(base_destination, job_id);
// the path to the file without the filename
var path_to_file_folder = path.dirname(file_path);
// the method to store a downloaded file to the fs
// makes an http request and writes the response to a file
@ttscoff
ttscoff / whereami.sh
Created July 2, 2014 16:08
Uses get-location/CoreLocation on a Mac and Google's geocoding API to tell you the street address of your current location
#!/bin/bash
# So you know whoami, but whereami?
# Relies on this handy hack <https://github.com/lindes/get-location>
latlong=$(/usr/local/bin/get-location 2> /dev/null \
| sed -e 's/.*<\(.*\)>.*/\1/')
address=$(curl -Ss "http://maps.googleapis.com/maps/api/geocode/json?latlng=$latlong&sensor=false" \
| grep formatted_address \
| head -n 1 \
| sed -e 's/[ \t]*"formatted_address" : "\(.*\)",/\1/')
@ghinda
ghinda / object-to-form-data.js
Last active May 21, 2024 20:48
JavaScript Object to FormData, with support for nested objects, arrays and File objects. Includes Angular.js usage.
// takes a {} object and returns a FormData object
var objectToFormData = function(obj, form, namespace) {
var fd = form || new FormData();
var formKey;
for(var property in obj) {
if(obj.hasOwnProperty(property)) {
if(namespace) {
@skreutzberger
skreutzberger / randomText.swift
Created August 12, 2015 13:53
generate random text in Swift
// returns random text of a defined length
// optional bool parameter justLowerCase
// to just generate random lowercase text
func randomText(length: Int, justLowerCase: Bool = false) -> String {
var text = ""
for _ in 1...length {
var decValue = 0 // ascii decimal value of a character
var charType = 3 // default is lowercase
if justLowerCase == false {
// randomize the character type
@skreutzberger
skreutzberger / randomColor.swift
Created August 12, 2015 14:38
generate random color in Swift
// returns a random color
func randomColor() -> UIColor{
let red = CGFloat(drand48())
let green = CGFloat(drand48())
let blue = CGFloat(drand48())
return UIColor(red: red, green: green, blue: blue, alpha: 1.0)
}
@plumhead
plumhead / StringSize.swift
Created September 15, 2015 13:34
String extension to find the layout size of a String with specified attributes.
extension String {
func size(withAttributes attrs: [String:AnyObject], constrainedTo box: NSSize) -> NSRect {
let storage = NSTextStorage(string: self)
let container = NSTextContainer(containerSize: NSSize(width: box.width, height: box.height))
let layout = NSLayoutManager()
layout.addTextContainer(container)
storage.addLayoutManager(layout)
storage.addAttributes(attrs, range: NSMakeRange(0, storage.length))
container.lineFragmentPadding = 0.0
let _ = layout.glyphRangeForTextContainer(container)
@paulirish
paulirish / what-forces-layout.md
Last active July 27, 2024 23:38
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent