Skip to content

Instantly share code, notes, and snippets.

View amir-s's full-sized avatar
:octocat:
Procrastinating

Amir Saboury amir-s

:octocat:
Procrastinating
View GitHub Profile
@amir-s
amir-s / degress2meters.js
Created February 7, 2021 00:26 — forked from springmeyer/degress2meters.js
convert from long/lat to google mercator (or EPSG:4326 to EPSG:900913)
// See https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames for more details.
var degrees2meters = function(lon,lat) {
var x = lon * 20037508.34 / 180;
var y = Math.log(Math.tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180);
y = y * 20037508.34 / 180;
return [x, y]
}
x= -77.035974
@amir-s
amir-s / ptr_inspect.c
Created February 24, 2018 01:41 — forked from willb/ptr_inspect.c
This is some example code showing how to use the ptrace system call under Linux to trace the system calls of a child process.
/*
ptr_inspect.c
Demonstration code; shows how to trace the system calls in a child
process with ptrace. Only works on 64-bit x86 Linux for now, I'm
afraid. (Even worse, it's only tested on Linux 2.6....)
The callname() function looks clunky and machine-generated because it
*is* clunky and machine-generated.
@amir-s
amir-s / count.js
Last active August 24, 2017 02:32
/*
0 1 2
3 4 5
6 7 8
*/
let cn = n => {
let c = 0;
while (n && ++c) n &= n-1;
return c;
const isEmpty = require('lodash/isEmpty');
const BaseQueryCompiler = require("knex/lib/query/compiler");
const BaseQueryBuilder = require("knex/lib/query/builder");
BaseQueryCompiler.prototype.replace = function replace() {
const insertValues = this.single.replace || [];
let sql = this.with() + `replace into ${this.tableName} `;
if (Array.isArray(insertValues)) {
if (insertValues.length === 0) {
return ''
/*
* A bit of hacky recursive solution, assuming you never pass 0 as the delay.
* ` arr[0] && ... rest ` this part is to prevent running rest of the things if we reach the end of the array.
* I'm using the the second parameter of sequence function just to run the function if the element is a function.
* This saves some characters. To check if the element is a function, I used `~~` which doesn't change the numeric
* values, but turnes functions to zero. So `~~arr[0] || arr[0]()` only runs the function if it is actually a func.
* I could also write `arr[0].call && arr[0]()`. But I like ~~ :D
* Same goes for `~~arr[0]` as the delay. If the element is fn, 0 would be the delay and it is going to be executed
* after 0ms.
*/
@amir-s
amir-s / url.js
Created December 24, 2015 03:20 — forked from anonymous/url.js
router.post('/search', function(req, res, next) {
// req.body.q has your search term, right? depends on the input name on the html.
res.redirect('/search?q=' + req.body.q);
});
router.get('/search', function(req, res, next) {
// you already got req.query.q if it is present. if not, it would be undefined
if (req.query.q) {
Product.search({query: req.query.q}, function(err, results) {
if (err) return next(err);
@amir-s
amir-s / pr.md
Last active August 29, 2015 14:15 — forked from piscisaureus/pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this: